Ad

Namespacing Controllers Within Routes File

- 1 answer

I have created a package which uses controllers from a certain namespace

Route::get('login', 'Full\Name\Space\Login\[email protected]');
Route::get('other', 'Full\Name\Space\Other\[email protected]');

Is there a 'Laravel' way to define the namespace once at the top of the routes file so I can shorten these controller paths? Something like

use 'Full\Name\Space';

Route::get('login', 'Login\[email protected]');
Route::get('other', 'Other\[email protected]');
Ad

Answer

Ofcourse you can:

Route::group(['namespace'=>'foo/1/2'],function(){
    Route::get('specify_your_route', '[email protected]')
});

Route will stay as "specify_your_route", but instead of \Base\Controller\Namespace\BarController router will use \foo\1\2\BarController

Ad
source: stackoverflow.com
Ad