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

rob_utopano's avatar

Getting "Route not defined" error

Hey guys,

i was creating a permission and role system for my webapplication with this tutorial: https://scotch.io/tutorials/user-authorization-in-laravel-54-with-spatie-laravel-permission

In the controller I must edit the route definitions because my views are stored in a subfolder so the route is called admin.permissions.index instead of permission.index.

The routes are fine and everything works but when I create a new permission I get an error that the Route admin.permissions.index is not defined. I am really sure that I ´ve changed every text phrase which contains the old route.

So what could be the error?

Best regards, Robert

0 likes
9 replies
srex's avatar

Did you do:

php artisan route:cache

or

php artisan route:clear

Just in case your routes are cached

rob_utopano's avatar

Hey @srex thanks for your answer. I´ve executed both commands but it changes nothing.

Here you can see the error which is displayed when I press my button (which calls the PermissionController)

https://prnt.sc/jstl7y

Best regards, Robert

srex's avatar

Oh I see did you create that named route? Because you're not actually loading a view directly, you're redirecting to a named route:

https://laravel.com/docs/5.6/helpers#method-route

Which is fine, but then you need to have defined the named route like so

Route::get('admin', 'AdminController@index')->name('admin.permissions.index')              

Can you show me your /routes/web.php file?

rob_utopano's avatar

Here are my routes (for my Permission-System)

Route::resource('users', 'UserController');

Route::resource('roles', 'RoleController');

Route::resource('permissions', 'PermissionController');

The problem is that the name can be index, create and edit, is it possible to give it a collection of names?

srex's avatar
srex
Best Answer
Level 16

Oh with resources it does it automatically.

You can just use:

php artisan route:list

Then you should be able to see the correct named route to redirect to

rob_utopano's avatar

@srex thanks for your answer

php artisan route:list

brings me an error like this:

  ReflectionException  : Class App\Http\Controllers\ContactUSController does not exist

The controller exists, where is the problem?

srex's avatar

Check the namespace and class name looks something like this (Check capitalization and spelling)


namespace App\Http\Controllers;

class ContactUSController  extends  Controller 
{
}

If that seems correct you should try to do the command:

composer dump-autoload
1 like
rob_utopano's avatar

Thank you very much @srex it works now! You helped me a lot!!!

Have a nice day. Best regards, Robert

1 like

Please or to participate in this conversation.