A Laravel form request answers 403 'This action is unauthorized'
403 This action is unauthorized.Short answer
A form request runs its authorize() method before the rules. If it returns false, Laravel stops with a 403 and the controller never runs. Check what authorize() returns for this request. The usual causes are a hard-coded false, a policy that denies the user, or a guest user that gates and policies reject by default.
Fix it fast
1Find out which cause you have
Open the form request class named in the controller method signature and read its authorize() method. Then dump what it returns for this request.
// app/Http/Requests/UpdatePostRequest.php public function authorize(): bool { dd($this->user(), $this->route('post')); }2Match what you see, then jump to its fix
- 1
The 403 appears on every request, for every user, and the request class has return false;authorize() simply returns falseFix - 2
authorize() calls $this->user()->can(...) and the 403 happens only for some users or some recordsA policy or gate denies this userFix - 3
403 on a route that is reachable without logging in, or on an API call that sent no valid session or tokenThe request comes from a guest, so $this->user() is nullFix
- 1
What does the error look like?
403 This action is unauthorized.Illuminate\Auth\Access\AuthorizationException: This action is unauthorized.The controller method is never reached and no validation errors are shown
Cause 1 of 3
authorize() simply returns false
1Check
Look at the body of authorize(). A request class that was edited or copied can still carry a fixed false.
grep -n -A3 'function authorize' app/Http/Requests/*.php2Fix
If the route is already protected by middleware or a policy elsewhere, return true. Otherwise return a real check.
public function authorize(): bool
{
return true;
}3Verify
Send the same request again. The 403 is gone and validation errors (422, or a redirect with errors) show instead.
php artisan test --filter=UpdatePostTestConfirmed by laravel.com
Cause 2 of 3
A policy or gate denies this user
1Check
Run the same check in tinker with the same user and model. If it prints false, the policy method (or the record's owner) is the cause. Also confirm the policy is found: its name must be the model name plus Policy, inside a Policies directory at or above the models.
php artisan tinker
>>> $user = App\Models\User::find(1);
>>> $user->can('update', App\Models\Post::find(1));2Fix
Correct the policy method, or register the policy by hand if the naming convention is not followed.
// app/Providers/AppServiceProvider.php, in boot()
Gate::policy(Post::class, PostPolicy::class);3Verify
Repeat the tinker call; it now prints true for a user who should be allowed.
>>> $user->can('update', $post);Confirmed by laravel.com
Cause 3 of 3
The request comes from a guest, so $this->user() is null
1Check
Gates and policies return false by default when the request was not made by an authenticated user. Check whether the route has the auth middleware and whether the client really sends its session or token.
php artisan route:list2Fix
Put the route behind the auth middleware so the user exists. If guests really may use it, make the user argument of the policy method optional with ?User so the check reaches your code.
public function update(?User $user, Post $post): bool
{
return $user?->id === $post->user_id;
}3Verify
Call the route once signed in and once as a guest and compare the two responses.
php artisan test --filter=PostPolicyTestConfirmed by laravel.com
How do I stop it coming back?
- Write one feature test per form request: an allowed user gets 200 or 302, a denied user gets 403.
- Keep authorization in policies and call them from authorize(), so the rule lives in one place.
- Use Response::deny('message') in policies so the 403 explains itself.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix