skip to Main Content

Task policy:

class TaskPolicy
{
    use HandlesAuthorization;

    public function canSeeTeam()
    {
        return true;
    }
}

AuthServiceProvider:

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        'AppModelsTask' => 'AppPoliciesTaskPolicy',
    ];

Task controller:

public function update(Request $request, Task $task)
    {      
        $this->authorize('canSeeTeam');
        dd('Authorized!');
    }

Instead of getting Authorized! I get:

"message": "This action is unauthorized.",
"exception": "SymfonyComponentHttpKernelExceptionAccessDeniedHttpException",

I’m logged in, and have access to the team, not it matters because canSeeTeam always true.

2

Answers


  1. Please send me error message or replace this:

     public function canSeeTeam()
        {
            return true; => return false;
        }
    
    Login or Signup to reply.
  2. You also have to pass the task object to the authorize method:

    $this->authorize('canSeeTeam', $task);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search