1

I using the laravel framework of php for development.I done these following steps

  1. I define Route::resource('users', 'UsersController'); in route file and then define Route::get('user/pingme', 'UserController@pingme');

  2. 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.

  3. then i changed it to Route::post('user/pingme', 'UserController@pingme'); it was working fine as needed.

  4. 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....

5
  • 1
    are you sure you need to use Route::resource() in this case? It's only used together with Resource Controllers. Commented Apr 16, 2014 at 10:57
  • yes in user controller ,i an creating storing user ,updating user. Commented Apr 16, 2014 at 11:00
  • Please show the relevant code. Commented Apr 16, 2014 at 11:13
  • here is the link for route and link for controller Commented Apr 16, 2014 at 11:37
  • did you run composer dump-autoload after changing the routes.php file ? Commented Apr 16, 2014 at 12:47

2 Answers 2

1

Route file works as follows:-

  1. 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');
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

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.