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 to block an IP address in .htaccess

How to replace whitespace with a single space

How to find the 2nd most common item in an array?

How to prevent Eloquent from adding created_at or updated_at timestamps?

How to query mysql using PDO in PHP?

PHP Date commonly used formats

What are the SPL Iterators in PHP?

How could you include a custom function for every single time PHP runs?

Is multiple inheritance supported in PHP?

How to find the intersection (same values) from two arrays?