How to namespace a Laravel route group?

Laravel: How to namespace a Laravel route group?

You can add a namespace for all items within a route group. If your controller (or controllers) are in app/Http/Controllers/AdminPanel then you could use the following code in your routes file (web.php):

  1. Route::group(["namespace"=>"AdminPanel"],function() {
  2.     Route::get("/","[email protected]"); // actually calls \App\Http\Controllers\AdminPanel\AdminControllers because of the namespace
  3. });

You can use relative (relative to the normal controller namespace - \App\Http\Controllers) or absolute (\App\Admin\Controllers\)

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 namespace a Laravel route 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 undelete a soft deleted Eloquent row?

How to set infinite execution time in a PHP script

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

Is multiple inheritance supported in PHP?

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

How to add the default charset to UTF-8 in .htaccess

When is __destruct called in PHP?

How to do comments in Blade files?

What is snake case?