what is the difference between static Route methods "resource" and "controller"
Route::controller()
and
Route::resource()
thanks,
I got something:
Route::resource()
but
Route::controller()
You can read about this in the official documentation:
http://laravel.com/docs/controllers#restful-controllers
Route::controller()
It will declare all routes you define as functions starting for html verbs, example from the documentation:
Route::controller('users', 'UserController');
class UserController extends BaseController {
public function getIndex()
{
//
}
public function postProfile()
{
//
}
public function anyLogin()
{
//
}
}
In other hand:
http://laravel.com/docs/controllers#resource-controllers
Route::resource()
Is basically used when you use the create controller command of artisan:
php artisan controller:make PhotoController
It will generate all the routes generated by the artisan command, basically crud routes.
Hope it helps you.
Here's the routing that occurs when you do both:
Route::controller('test', 'TestController');
Route::resource('othertest', 'OtherTestController');
Here's a picture of what I'm about to write out in text for you, if it's any easier:
The following is an all-in-one. For example, if you GET
to laravel_dir/test/page
, it will look for method getPage()
in TestController
. If you POST
to laravel_dir/test/page
, it will look for postPage()
URI: GET|HEAD|POST|PUT|PATCH|DELETE test/{_missing}
Route Name: None
Action: TestController@missingMethod
Below is what results from the resource route... You'll see that it is very useful for CRUD in one line for your routes.php file.
URI: GET|HEAD othertest
Route Name: othertest.index
Action: OtherTestController@index
URI: GET|HEAD othertest/create
Route Name: othertest.create
Action: OtherTestController@create
URI: POST othertest
Route Name: othertest.store
Action: OtherTestController@store
URI: GET|HEAD othertest/{othertest}
Route Name: othertest.show
Action: OtherTestController@show
URI: GET|HEAD othertest/{othertest}/edit
Route Name: othertest.edit
Action: OtherTestController@edit
URI: PUT othertest/{othertest}
Route Name: othertest.update
Action: OtherTestController@update
URI: PATCH othertest/{othertest}
Route Name: othertest.update (shares the name with the above)
Action: OtherTestController@update
URI: DELETE othertest/{othertest}
Route Name: othertest.destroy
Action: OtherTestController@destroy
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