hotel
This commit is contained in:
77
app/Http/Controllers/Admin/HotelController.php
Normal file
77
app/Http/Controllers/Admin/HotelController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Hotel;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HotelController extends Controller
|
||||
{
|
||||
/**
|
||||
* Показать список отелей.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$hotels = Hotel::all();
|
||||
return response()->view('admin/hotels/index', compact('hotels'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Показать форму создания отеля.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.hotels.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохранить новый отель.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'address' => 'nullable|string',
|
||||
'phone' => 'nullable|string',
|
||||
]);
|
||||
|
||||
Hotel::create($validated);
|
||||
|
||||
return redirect()->route('admin.hotels.index')->with('success', 'Отель добавлен!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Показать форму редактирования отеля.
|
||||
*/
|
||||
public function edit(Hotel $hotel)
|
||||
{
|
||||
return view('admin.hotels.edit', compact('hotel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновить отель.
|
||||
*/
|
||||
public function update(Request $request, Hotel $hotel)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'address' => 'nullable|string',
|
||||
'phone' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$hotel->update($validated);
|
||||
|
||||
return redirect()->route('admin.hotels.index')->with('success', 'Отель обновлён!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Удалить отель.
|
||||
*/
|
||||
public function destroy(Hotel $hotel)
|
||||
{
|
||||
$hotel->delete();
|
||||
|
||||
return redirect()->route('admin.hotels.index')->with('success', 'Отель удалён!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user