Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Esekien's avatar

Laravel policies without user

Hello everyone, I have a question, I hope you can help me. In my application with Laravel 8 I want to integrate polices, however I do not have a Users table or Users Model, since I log in with the consumption of an external API where I log in. I understand that in the polices you have to pass the Users by default as a parameter, but would there be the possibility of integrating it without it? public function preview() { $this->authorize('validator'); return 'preview'; } my police public function validator(?User $user) { return true; }

this returns me that I do not have permissions

0 likes
2 replies
click's avatar

This should be possible, you have to pass the model you are trying to call validate on as the second parameter.

// controller
$this->authorize('validator', Post::class);
// PostPolicy.php
public function validator(?User $user, Post $post)
{
     return true; 
}

"Guest Users" https://laravel.com/docs/9.x/authorization#guest-users

1 like
Esekien's avatar

Try what you mention I give the example:

	// controller
    public function preview()
    {
        $this->authorize('validator',Student::class);
        return 'preview';
    }
// StudentPolicy
    public function validator(?User $use, Student $student)
    {
        return true;
    }

but it keeps telling me that I don't have permissions :(

Please or to participate in this conversation.