feature: add delete parking lot with active bookings guard and image cleanup

This commit is contained in:
ghassan committed 2026-04-15 15:57:04 +03:00
1 parent c6d2d98cc8
commit bf82e331d1
4 files changed
+54 -1

No files matched your search

@@ -68,6 +68,29 @@ class ParkingLotController extends Controller
]);
}
public function destroy(ParkingLot $parkingLot): JsonResponse
{
// Block deletion if there are active bookings
$activeCount = $parkingLot->bookings()->where('status', 'active')->count();
if ($activeCount > 0) {
return response()->json([
'success' => false,
'message' => "لا يمكن الحذف — يوجد {$activeCount} حجز نشط في هذا الموقف",
], 422);
}
if ($parkingLot->image) {
Storage::disk('public')->delete($parkingLot->image);
}
$parkingLot->delete();
return response()->json([
'success' => true,
'message' => 'تم حذف الموقف بنجاح',
]);
}
public function toggleStatus(ParkingLot $parkingLot): JsonResponse
{
$parkingLot->update(['is_active' => !$parkingLot->is_active]);