1

When I use my route like this, the test route is working fine.
Route:-

Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController@myFavorite');
Route::get('user/test','UserController@test'); // is working
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'USerController@planed']);
.
.
.
.

But when I want to use it like following, it shows a blank page :

Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController@myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController@planed']);
Route::get('user/test','UserController@test'); // is not working
.
.
.
.

What is my mistake?

3
  • 1
    What do you mean by "it isn't working?" what is happening exactly? I can see that you have the test route in the auth middleware group, so maybe that could be why. But again, can you please clarify what exactly is happening? Commented Jul 17, 2017 at 6:07
  • @AaronFahey test method in controller prints a query output : $users = Subscriber::where('user_id', $this->_userId)->pluck('user_id'); dd($users); - it is working before resource but shows a blank page after putting the route inside Auth middlware after resource Commented Jul 17, 2017 at 6:12
  • I am testing it by a logged in user Commented Jul 17, 2017 at 6:13

2 Answers 2

1

Because the call to test is intercepted by

Route::resource('user', 'UserController');

because if you check the routes in the console with

$> php artisan route:list

you'll see it includes

GET|HEAD  | user/{user}

and then your first route

Route::get('user/test','UserController@test'); // is not working

is never reached. Try to put it BEFORE the other line.

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

6 Comments

You mean route resource for User should be put after all user routes? I thought laravel Resource only intercept index, create , update ,.... routes!!
as you see user/planed route is working, and it is after resource
When I use the route like this: Route::get('user/test/{id}','UserController@test');, it is working!!! why? I do not need id wild card
Did you at least try what I suggested?
Yes @Amarnasan, I tried and it worked! but what is wrong with my code ? Do I have to always put all routes after Resourse route ?
|
1

I thing the issue in naming the route check This

Try like this

Route::group(array('namespace' => '\User'), function () {
Route::get('user/my-favorite','UserController@myFavorite');
Route::resource('user', 'UserController');
Route::group(['middleware' => ['auth']], function () {
Route::get('user/planed','UserController@planed'])->name('user.planed');
Route::get('user/test','UserController@test'); // is not working

Just replace

Route::get('user/planed',['as' => 'user.planed', 'uses' => 'UserController@planed']);

With

Route::get('user/planed','UserController@planed'])->name('user.planed');

8 Comments

Tried, didn't work. event is I put test route just after resource, is not working! blank page without error
Your ['middleware' => ['auth']] is working fine or not ?
Yes it it is working for other routes in this middleware
When I use the route like this: Route::get('user/test/{id}','UserController@test');, it is working!!! why? I do not need id wild card
Just change the route name astest2 and remove {id} and try it again
|

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.