make permission for plan edit only author can edit his plan

This commit is contained in:
2024-01-18 00:46:33 +03:00
parent 276e8babce
commit 8d1aee4995
8 changed files with 68 additions and 4 deletions

View File

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