Answer the question
In order to leave comments, you need to log in
Why is laravel policy not working?
Good afternoon!
Prompt, created RolesPolicy.
added the following
protected $policies = [
Roles::class => RolesPolicy::class,
];
$role = Menu::where('route', $this->currentRouteName())->first();
$roles = new \App\Models\Roles;
$this->authorize('view', $request->user(), $roles);
namespace App\Policies;
use App\Models\User;
use App\App\Models\Roles;
use Illuminate\Auth\Access\HandlesAuthorization;
class RolesPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the roles.
*
* @param \App\Models\User $user
* @param \App\App\Models\Roles $roles
* @return mixed
*/
public function view(User $user, Roles $roles)
{
return false;
}
}
Answer the question
In order to leave comments, you need to log in
The user is injected into the Policy automatically, you only need to specify what you want to do and with what:$this->authorize('view', $roles);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question