myol
myol

Reputation: 9828

Namespacing controllers within routes file

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

Route::get('login', 'Full\Name\Space\Login\LoginController@method');
Route::get('other', 'Full\Name\Space\Other\OtherController@method');

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\LoginController@method');
Route::get('other', 'Other\OtherController@method');

Upvotes: 2

Views: 53

Answers (1)

ssuhat
ssuhat

Reputation: 7656

Ofcourse you can:

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

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

Upvotes: 3

Related Questions