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?
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');
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.
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'
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With