Files
app3/app/Http/Controllers/Admin/HotelController.php
2026-01-12 18:20:31 +00:00

78 lines
1.9 KiB
PHP

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