Laravel stops with UnexpectedValueException: Invalid route action
UnexpectedValueException: Invalid route action: [App\Http\Controllers\UserController].Short answer
Laravel throws Invalid route action when a route's controller string has no @method part and Laravel therefore treats it as a single-action controller, but the class has no __invoke method or cannot be loaded. Name the method in the route with the array form, or add __invoke, or fix the class name that the bracketed text shows.
Fix it fast
1Find out which cause you have
Find the route file and line behind the error in the log, then read the text inside the square brackets. It is the exact string Laravel failed to turn into a controller and method.
grep -m1 -A14 "Invalid route action" storage/logs/laravel.log2Match what you see, then jump to its fix
- 1
The brackets hold a clean class name only, such as [App\Http\Controllers\UserController]The route names a controller class but the class has no __invoke methodFix - 2
The brackets show the whole string including the stray character, such as [UserController:index] or [UserController.index]The old string syntax has a mistyped separatorFix - 3
A class-only route, and the bracketed name has a wrong namespace, a typo, or a file name with different letter caseThe class in the route cannot be loadedFix
- 1
What does the error look like?
UnexpectedValueException: Invalid route action: [App\Http\Controllers\UserController].In RouteAction.php line 84: Invalid route action
Cause 1 of 3
The route names a controller class but the class has no __invoke method
1Check
A route written as Route::get('/users', UserController::class) means "run this class as a single-action controller". Laravel then looks for an __invoke method. A normal controller with index() or show() has none.
grep -n "__invoke" app/Http/Controllers/UserController.php2Fix
Add the method name to the route with the array form. Keep the class-only form for a controller that really has one __invoke method.
use App\Http\Controllers\UserController;
Route::get('/users', [UserController::class, 'index']);3Verify
The route loads and appears in the list.
php artisan route:list --path=usersConfirmed by laravel.com
Cause 2 of 3
The old string syntax has a mistyped separator
1Check
In the string form the class and method are joined by an at sign. When there is no @ in the string, Laravel does not split it. It treats the entire string as one class name and runs the same __invoke check, which fails.
grep -rnE "Controller[:.][A-Za-z]+['\"]" routes/2Fix
Replace the string with the array form, which cannot lose its separator.
// before
Route::get('/users', 'UserController:index');
// after
Route::get('/users', [UserController::class, 'index']);3Verify
The command that failed now runs.
php artisan route:listConfirmed by raw.githubusercontent.com
Cause 3 of 3
The class in the route cannot be loaded
1Check
For a class-only route Laravel calls method_exists() with the name. That function returns false when the method is not defined, and also when PHP cannot find the class even after trying the autoloaders. The error is then the same as a missing __invoke.
php -r 'require "vendor/autoload.php"; var_dump(class_exists("App\\Http\\Controllers\\UserController"));'2Fix
Correct the namespace, the use import or the file name so the class loads. File and class names must match in letter case, because the autoloader maps a name to a path.
// app/Http/Controllers/UserController.php
namespace App\Http\Controllers;
class UserController extends Controller
{
// ...
}3Verify
class_exists now prints bool(true) for the name in the brackets.
php -r 'require "vendor/autoload.php"; var_dump(class_exists("App\\Http\\Controllers\\UserController"));'Confirmed by php.net
How do I stop it coming back?
- Write every controller route in the array form, [Class::class, 'method'], so the method is always named.
- Create single-action controllers with php artisan make:controller Name --invokable, so __invoke exists.
- Run php artisan route:list in CI to catch a bad route before it reaches the server.
- Match each controller file name to its class name, letter for letter.
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
Laravel cannot find your controller: Target class does not exist
ReflectionException: Class App\Http\Controllers\UserController does not exist
Laravel 8 stopped adding the App\Http\Controllers prefix to controller names in route files.
3 causes, each with a fixBack 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 fix