Files
app3/app/Http/Controllers/Admin/HotelController.php
2026-01-26 09:06:06 +00:00

72 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Hotel;
use Illuminate\Http\Request;
use App\Models\RoomType;
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 calendar(Request $request, $hotelId)
{
$hotel = \App\Models\Hotel::findOrFail($hotelId);
$roomTypes = RoomType::where('hotel_id', $hotelId)->with('availabilities')->get();
if ($request->ajax()) {
return view('admin.hotels._calendar', compact('hotel', 'roomTypes'))->render();
}
return view('admin.hotels.calendar', compact('hotel', 'roomTypes'));
}
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', 'Отель удалён.');
}
}