Explain, please, what is the purpose of 'as' and 'uses'. I do not understand the principle of these words.

Route::get('user/profile', array('as' => 'profile', 'uses' => 'UserController@showProfile')); 

    1 answer 1

    as - works as a prefix to the route, in your case it is better to simply replace as with the name method:

     Route::get('user/profile', array('uses' => 'UserController@showProfile'))->name('profile'); 

    If you would leave 'as' => 'profile' and write the name('profile') then in the end route name would be profileprofile .

    uses - says which controller to use and method, in your case it is also not necessary, it is easier to do this:

     Route::get('user/profile', 'UserController@showProfile')->name('profile'); 

    Easier and clearer.

    UPD. About the name method and how to use it is described in the documentation.

    • So, as I understand it, when you click on the / user / profile link, the showProfile method (function) will be executed in the UserController controller. What is the name method ('profile') for? Where to register? - Ivan
    • As I gave in the example above, the name method is needed to create a url by name, for example, you want to change the link, and you have to search everywhere where this link was and change it to a new one, here name allows you to get rid of it, read the documentation: laravel.com /docs/5.3/routing#named-routes (this is English, it should also be in Russian) - Yaroslav Molchan