Merge branch 'issue-8' into 'develop'

Detach products/recipes at deletion

Closes #8

See merge request ldc-web/projets/nature-and-respect!11
This commit is contained in:
Vincent BRIDIER 2023-06-01 13:22:11 +00:00
commit c69f42a1b0
2 changed files with 28 additions and 22 deletions

View file

@ -158,19 +158,22 @@ class ProductController extends Controller
*/
public function destroy(Product $product)
{
if ($product->deleteOrFail()) {
return DB::transaction(function () use ($product) {
$product->recipes()->detach();
if ($product->deleteOrFail()) {
return redirect()
->route('bo.products.index')
->with('success', trans(
'crud.messages.has_been_deleted',
['model' => Str::singular(trans('models.classes.products'))]
));
}
return redirect()
->route('bo.products.index')
->with('success', trans(
'crud.messages.has_been_deleted',
->back()
->with('error', trans(
':crud.messages.cannot_be_deleted',
['model' => Str::singular(trans('models.classes.products'))]
));
}
return redirect()
->back()
->with('error', trans(
':crud.messages.cannot_be_deleted',
['model' => Str::singular(trans('models.classes.products'))]
));
});
}
}

View file

@ -146,19 +146,22 @@ class RecipeController extends Controller
*/
public function destroy(Recipe $recipe)
{
if ($recipe->deleteOrFail()) {
return DB::transaction(function () use ($recipe) {
$recipe->products()->detach();
if ($recipe->deleteOrFail()) {
return redirect()
->route('bo.recipes.index')
->with('success', trans(
'crud.messages.has_been_deleted',
['model' => Str::singular(trans('models.classes.recipes'))]
));
}
return redirect()
->route('bo.recipes.index')
->with('success', trans(
'crud.messages.has_been_deleted',
->back()
->with('error', trans(
':crud.messages.cannot_be_deleted',
['model' => Str::singular(trans('models.classes.recipes'))]
));
}
return redirect()
->back()
->with('error', trans(
':crud.messages.cannot_be_deleted',
['model' => Str::singular(trans('models.classes.recipes'))]
));
});
}
}