Delmontee
Delmontee

Reputation: 2364

Laravel 4 how to use the route name alias (uses) with Route::controller

Rather than using Route::get, Route::post etc for my controller requests I decided to use the Route::controller method, really helps cut down on code lines in route.php.

However I had previously set up some "route" names, for example my previous code included:

Route::get('admin/baserate/view', array('as' => 'baserateview','uses'=>'BaserateController@getView'));

but now I'm using Route::controller I don't know how to implement the route alias name "baserateview". My new code looks like:

Route::controller('admin/baserate', 'BaserateController');

Is there any way I can do this?

Upvotes: 8

Views: 11336

Answers (2)

Andrew Halls
Andrew Halls

Reputation: 350

You can do this in the following way:

// User Controller
Route::controller(
    'users',
    'AdminUserController',
    array(
        'getView'     => 'admin.users.view',
        'getEdit'     => 'admin.users.edit',
        'getList'     => 'admin.users.list',
        'getAdd'      => 'admin.users.add',
        'getUndelete' => 'admin.users.undelete',
        'postDelete'  => 'admin.users.delete'
    )
);

Upvotes: 22

Delmontee
Delmontee

Reputation: 2364

Ok so it isn't possible to do it all on the Route:controller line. I'd have to go with both lines:

Route::controller('admin/baserate', 'BaserateController');
Route::get('admin/baserate/view', array('as' => 'baserateview','uses'=>'BaserateController@getView'));

...which works fine. I was just hoping that there would be a way to specify that one of the methods inside the controller has a named route without having to use two lines

Thanks anyway

Upvotes: -1

Related Questions