63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
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 store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'address' => 'nullable|string',
|
|
]);
|
|
|
|
$hotel = Hotel::create($validated);
|
|
|
|
return response()->json($hotel, 201);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$hotel = Hotel::findOrFail($id);
|
|
|
|
return response()->json($hotel);
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$hotel = Hotel::findOrFail($id);
|
|
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'address' => 'nullable|string',
|
|
]);
|
|
|
|
$hotel->update($validated);
|
|
|
|
return response()->json($hotel);
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$hotel = Hotel::findOrFail($id);
|
|
|
|
|
|
//if ($hotel->bookings()->exists()) {
|
|
// return response()->json(['error' => 'Cannot delete hotel with bookings'], 400);
|
|
//}
|
|
|
|
$hotel->delete();
|
|
|
|
return response()->json(['message' => 'Hotel deleted successfully']);
|
|
}
|
|
} |