Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 973
James Avatar asked Dec 12 '13 13:12

James


People also ask

How can we name a route in Laravel?

You can specify named routes by chaining the name method onto the route definition: Route::get('user/profile', function () { // })->name('profile'); You can specify route names for controller actions: Route::get('user/profile', 'UserController@showProfile')->name('profile');

Why do we use name in route in Laravel?

Named routes is an important feature in the Laravel framework. It allows you to refer to the routes when generating URLs or redirects to the specific routes. In short, we can say that the naming route is the way of providing a nickname to the route.


1 Answers

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'
    )
);
like image 94
Andrew Halls Avatar answered Jan 04 '23 10:01

Andrew Halls