How to namespace a Laravel route group?

October 26, 2018

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):

<?php
Route::group(["namespace"=>"AdminPanel"],function() {
    Route::get("/","AdminController@index"); // actually calls \App\Http\Controllers\AdminPanel\AdminControllers because of the namespace
});

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