Validaciones y Zonas de produccion

This commit is contained in:
2021-07-12 11:05:50 -04:00
parent 4f1dfd1221
commit d64dacee8d
9 changed files with 186 additions and 2 deletions

View File

@@ -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);
}