This commit is contained in:
2026-01-12 18:20:31 +00:00
parent 2a83373b28
commit ff904abf49
10 changed files with 244 additions and 19 deletions

View 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', 'Отель удалён!');
}
}

View File

@@ -10,7 +10,8 @@ class HotelController extends Controller
{
public function index()
{
return Hotel::all();
$hotels = Hotel::all();
return view('admin.hotels.index', compact('hotels'));
}
public function store(Request $request)