I'm working with Laravel 8, and I have a resource Controller named Profile
. And within this Controller, users can edit their user profile information.
So at the edit
method, I put this:
public function edit(User $user)
{
$this->authorize('edit-user', $user);
return view('editprofile', compact('user'));
}
And users can access editprofile
blade by this button:
<a href="{{ route('profile.edit' , ['profile' => Auth::user()->id]) }}" class="btn">Edit Profile</a>
But now the problem is, it returns this:
403 THIS ACTION IS UNAUTHORIZED.
However I am already logged in and I want to access my own profile.edit
and not other users!
So if you know why am I getting this error, please let me know, I would really appreciate any idea or suggestion from you guys...
Thanks.
And here is also my route:
Route::middleware('auth')->group(function() {
Route::resource('profile' , ProfileController::class);
});
UDPATE 1:
Please change the followings
public function edit (Request $request, User $profile) {
Gate::allows('edit-user', $profile);
// do the logic
}