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

58 lines
1.5 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 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|max:20',
]);
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|max:20',
]);
$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', 'Отель удалён.');
}
}