1
Route::resource('posts','PostsController');
Route::post('posts/changeStatus', array('as' => 'changeStatus', 'uses' => 'PostsController@changeStatus'));

The code provided is a route from my laravel project. I did not write this code and I am attempting to understand what they have done. I cannot find anywhere in the documentation the reason for using the key value store with 'as' and 'uses'. I would normally write the code below, however this is not working with the ajax-crud setup.

Route::post('posts/changeStatus', 'PostsController@changeStatus');
3
  • it is used for named routes Commented Dec 29, 2017 at 7:32
  • these are named routes, laravel.com/docs/5.1/routing#named-routes Commented Dec 29, 2017 at 7:33
  • You can write Route::post('posts/changeStatus', 'PostsController@changeStatus')->name('changeStatus') instead. Commented Dec 29, 2017 at 7:37

1 Answer 1

1

From the docs:

Named routes allow you to conveniently generate URLs or redirects for a specific route. You may specify a name for a route using the as array key when defining the route

as is the name of that route. You can use it to create an URL with route('changeStatus') helper.

uses is controller method (action) for the route.

https://laravel.com/docs/5.1/routing#named-routes

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I was looking at the latest docs 5.5 which did not mention this. Big help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.