Validaciones y Zonas de produccion
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Restaurante;
|
||||
use App\Services\PaginatorService;
|
||||
use App\Services\UuidService;
|
||||
use App\Exceptions\GenericException;
|
||||
use App\Exceptions\CantDeleteHasChildException;
|
||||
use App\Exceptions\ModelNotFoundException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -92,6 +93,13 @@ class RestaurantesController extends Controller {
|
||||
app(UuidService::class)->validOrFail($id);
|
||||
|
||||
$restaurant = Restaurante::findOrFail($id);
|
||||
|
||||
if($restaurant->usuarios()->count() > 0) throw new CantDeleteHasChildException("restaurant", "usuario");
|
||||
if($restaurant->canalesVenta()->count() > 0) throw new CantDeleteHasChildException("restaurant", "canal_venta");
|
||||
if($restaurant->sectores()->count() > 0) throw new CantDeleteHasChildException("restaurant", "sector");
|
||||
if($restaurant->zonasProduccion()->count() > 0) throw new CantDeleteHasChildException("restaurant", "zona_produccion");
|
||||
|
||||
|
||||
$restaurant->delete();
|
||||
return response()->json([], 204);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user