i want to use custom function in Route::resource()
controller like with public function check()
, public function login()
or public function laogout()
, but my code doesnt work, how to use custom functions?
For Example:
Route:
Route::resource('auth', 'AuthenticationController');
View:
Controller:
public function check()
{
//
}
public function login()
{
//
}
public function logout()
{
//
}
I get this error:
NotFoundHttpException in RouteCollection.php line 161:
Firstly, resource controllers should be used to generate Restful API that provides CRUD interface to your application - not for logging users in and out.
Secondly, you can't add additional controller methods with Route::resource() - this method is used to define the prefixed set of methods - see http://laravel.com/docs/5.1/controllers#restful-resource-controllers for more information.
If you want to add those custom actions to your routing, you'll need to define them separately before your resource routes, e.g.:
Route::get('auth/check', 'AuthenticationController@check');
You can read more about defining custom routes here: http://laravel.com/docs/5.1/routing
If you use custom function in route resource,you need to define your request type with function name,like this
Route::POST('auth/save-comment','authController@customFunctionName');