forked from eatvio/eatvio-infra
make permission for plan edit only author can edit his plan
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\User;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
@@ -41,6 +42,15 @@ class PlanController extends Controller
|
||||
|
||||
public function edit(Plan $plan): View|ViewFactory
|
||||
{
|
||||
if (! $this->canEditPlan($plan)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
return view('plan/edit_form', ['plan' => $plan]);
|
||||
}
|
||||
|
||||
private function canEditPlan(Plan $plan): bool
|
||||
{
|
||||
return Gate::allows('edit', $plan);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user