forked from eatvio/eatvio-infra
make permission for recipe edit
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Recipe;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class RecipeController extends Controller
|
||||
{
|
||||
@@ -37,6 +38,14 @@ class RecipeController extends Controller
|
||||
|
||||
public function edit(Recipe $recipe): View|ViewFactory
|
||||
{
|
||||
if (! $this->canEditRecipe($recipe)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
return view('recipe/edit_form', ['recipe' => $recipe]);
|
||||
}
|
||||
|
||||
private function canEditRecipe(Recipe $recipe): bool
|
||||
{
|
||||
return Gate::allows('edit', $recipe);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user