Juliatzin
Juliatzin

Reputation: 19695

Laravel Policies never called

I'm trying to apply a policy on a TeamController:

TeamPolicy is :

public function before(User $user, $ability)
{
    if ($user->isSuperAdmin()) {
        return true;
    }
    return null;
}


public function create(User $user, Tournament $tournament)
{
    return $user->isOwner($tournament);
}

In my controller I call it this way:

public function create(Tournament $tournament)
{
    $team = new Team;
    if (Auth::user()->cannot('create', $team)) {
        throw new UnauthorizedException();
    }
}

I dd inside both functions, but never get called.

Any idea what's wrong???

Upvotes: 0

Views: 1075

Answers (1)

seven77
seven77

Reputation: 380

Have you registered your policy in the AuthServiceProvider, like so: https://laravel.com/docs/5.2/authorization#creating-policies ?

Upvotes: 1

Related Questions