Reputation: 739
I using the laravel framework of php for development.I done these following steps
I define Route::resource('users', 'UsersController');
in route file and then define Route::get('user/pingme', 'UserController@pingme');
When i make a get call to pingme function, it was not working .I was getting the response code is 200
but code inside that pingme
function was not working and i do not know why.
then i changed it to Route::post('user/pingme', 'UserController@pingme');
it was working fine as needed.
then what i did is, removed Route::resource('users', 'UsersController');
and make again get route to ping me function and make get call and it starts working fine .
so this is any bug in framework(rare thing) or i am missing something(probably yes)? Help me out....
Upvotes: 1
Views: 118
Reputation: 381
Route file works as follows:-
if you have wrote a mapping for controller only, then it needs to come at the bottom of all other route mapping otherwise your program controller will pick route from user controller only and will redirect to UserController. so the right order of all routes is:-
Route::get('user/pingme', 'UserController@pingme');
Route::post('user/logout', 'UserController@logout')->before('auth');
Route::resource('user', 'UserController');
OR
Route::post('user/logout', 'UserController@logout')->before('auth');
Route::get('user/pingme', 'UserController@pingme');
Route::resource('user', 'UserController');
Upvotes: 1
Reputation: 5240
In your route file, the order of the routes needs to be as follows:
Route::get('user/pingme', 'UserController@pingme');
Route::post('user/logout', 'UserController@logout')->before('auth');
Route::resource('user', 'UserController');
If Route::resource('user', 'UserController')
comes before the other routes, the GET
request to user/pingme
will be handled by show
method inside of UserController
, because it is how Resourceful Controllers work. So, the Route::resource
for user
needs to come after all other routes with user/
prefix.
Upvotes: 0