[Vuejs]-Why does my Laravel policy always return false?

0👍

As you created policy userOwnedClassPolicy and set it for userOwnedClass model in AuthServiceProvider here:

App\Models\userOwnedClass::class => App\Policies\userOwnedClassPolicy::class

you cannot just run policy method:

$this->authorize('create', Auth::user());

When you run this line above, you tell – check create method for policy for \App\Models\User object, but you don’t have any policy created for this model.

So in this case you should run it like so:

$this->authorize('create', \App\Models\userOwnedClass::class);

Then Laravel will know that it should run create method from userOwnedClassPolicy policy and it will automatically pass currently authenticated user into $user variable in policy method.

Leave a comment