migration
This commit is contained in:
62
app/Http/Controllers/HotelController.php
Normal file
62
app/Http/Controllers/HotelController.php
Normal 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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user