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 hide certain file types from directory listings

How to query mysql using PDO in PHP?

How to create random numbers in JS?

How to install and use optipng on Linux CentOS

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

How to block an IP range based on CIDR in Apache with .htaccess

How to return an item in Eloquent, or throw a ModelNotFoundException exception if it isn't found?

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

How to select what columns to return when calling ::all()

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