migration

This commit is contained in:
2026-01-07 22:18:43 +00:00
parent 8d681da7a1
commit 66cddf3fb2
29 changed files with 2250 additions and 638 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Http\Controllers;
use App\Models\Hotel;
use Illuminate\Http\Request;
class HotelController extends Controller
{
public function index()
{
return Hotel::all();
}
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']);
}
}