Reputation: 1235
I have a route like this:
Route::group(['prefix'=>'admin'],function(){
Route::resource('users','UserController'); // <-- what is the name of this route
});
How can I address the users
route by its name e.g route('users')
?
I tested users
and admin.users
but it didn't help.
Upvotes: 3
Views: 8551
Reputation: 31
use this
Route::group(['as'=>'admin.' ,'prefix'=>'admin'],function(){
Route::resource('users','UserController');
});
the name of route will be
admin.users.index
admin.users.create
admin.users.store
admin.users.edit
admin.users.update
admin.users.destroy
admin.users.show
Upvotes: 3
Reputation: 7324
By using php artisan route:list
command print all the routs to the terminal and see its names. it will show users.index
, users.create
, users.update
and so on.
usage:
route('users.index');
//output: example.com/admin/users
Upvotes: 0
Reputation: 136
When you register a resourceful route to the controller Route::resource(...)
, this simple declaration creates multiple routes to handle a variety of actions (list of all actions).
So inside admin
route group you will have such names for routes:
admin.users.index
for GET admin/users
admin.users.store
for POST admin/users
admin.users.show
for GET admin/users/{id}
Basically, you can list all route names using php artisan route:list
Upvotes: 8
Reputation: 2534
It's admin/users
.
The url of the controllers in group will be group prefix then controller resource name. prefix/resource
Upvotes: 2