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

What is Agile software development?

How to find out which php.ini file PHP is using?

How to convert between types in JS?

How to have a whitelist of IP addresses that can access files in .htaccess

How to find the average value of items in a Laravel Collection?

How to view all installed PHP modules?

How to manually write your own pagination in PHP

How to Enable Directory Listings in Apache with .htaccess

How to replace whitespace with a single space

How does PHP compare objects?