I have defined a Policy named UserPolicy
which goes like this:
class UserPolicy
{
use HandlesAuthorization;
public function edit(User $user)
{
if(Gate::allows('edit', $user)){
return view('admin.users.edit' , compact('user'));
}
abort(403);
}
}
And at AuthServiceProvider.php
, I have called it like this:
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
User::class => UserPolicy::class
];
Then at the Blade, I added this:
@can('edit', $user)
<a href="{{ route('users.edit' , ['user' => $user->id]) }}" class="btn btn-sm btn-primary">Edit</a>
@endcan
But now, I get this error:
Class 'App\Policies\Gate' not found
How can I fix this issue?
Look like you have not imported Gate
facade in UserPolicy
class
use Illuminate\Support\Facades\Gate;