How to add a name prefix to all routes in a group?

Laravel: How to add a name prefix to all routes in a group?

You can use Route Name Prefixes. If you wanted to have a group of Laravel routes all with names like 'admin.users', 'admin.news', etc then you can use a route name prefix to prepend 'admin.' to the start of all of the names

  1. Route::name('admin.')->group(function () {
  2.     Route::get('users', function () {
  3.          })->name('users'); // Route will have the name "admin.users"...
  4.  
  5. });

However I do not like doing this, as it means I can't easily search for a particular route. But it does have the advantage of enforcing all in a group to have the same naming structure.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to add a name prefix to all routes in a group?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How do you launch the PHP interactive shell?

How to get the first row that matches some where queries, or create it if it doesn't exist (in Laravel's Eloquent)?

How to prevent Eloquent from adding created_at or updated_at timestamps?

How to add the CSRF (Cross-site request forgery) token in Laravel?

What is WordPress default Apache .htaccess rules?

How to select all rows for a certain month (or day, year or time), using Eloquent

What is the difference between var, let and const in Javascript?

How to review blog posts (written by other users) before they get published on your WordPress blog?

How to set custom HTTP headers in Apache (by editing .htaccess)

What are macros in Laravel?