forked from eatvio/eatvio-infra
added permission for diet
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Spatie\QueryBuilder\AllowedFilter;
|
||||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class DietController extends Controller
|
||||
{
|
||||
@@ -51,6 +52,10 @@ class DietController extends Controller
|
||||
|
||||
public function edit(Diet $diet): View
|
||||
{
|
||||
if (! $this->canEditDiet($diet)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
return view('diet/edit_form', ['diet' => $diet]);
|
||||
}
|
||||
|
||||
@@ -64,4 +69,9 @@ class DietController extends Controller
|
||||
|
||||
return view('diet/show', ['diet' => $diet]);
|
||||
}
|
||||
|
||||
private function canEditDiet(Diet $diet): bool
|
||||
{
|
||||
return Gate::allows('edit', $diet);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user