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
Did you do:
php artisan route:cache
or
php artisan route:clear
Just in case your routes are cached
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
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?
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?
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
@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?
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
Thank you very much @srex it works now! You helped me a lot!!!
Have a nice day.
Best regards,
Robert
Please sign in or create an account to participate in this conversation.