1

I have one route in my routes.php like

Route::get('{subcat}', array(
  'uses'  => 'frontend\homeController@uploadAd'
))

And I found that the above route is effecting my userlogout route which is like this.

Route::get('userlogout', array(
   'uses' => 'frontend\homeController@userlogout'
));

I am getting the {subcat} route parameter from the blade view like

<a href="{{ subcategoryslug}}">subcategoryname</a>

If I include my {subcat} route in routes.php, userlogout route does not work but, commenting out my {subcat} route or even modifying that route like:

 Route::get('something/{subcat}', array(
      'uses'  => 'frontend\homeController@uploadAd'
    ))

enable user to log out from the system.

What am I doing wrong here? Is there anything that I can't specify only route parameter as my route name?

2
  • 1
    Have you tried writing the userlogout route BEFORE the subcat route? Commented Sep 4, 2015 at 7:40
  • @Amarnasan got it.. Thanks Commented Sep 4, 2015 at 7:45

1 Answer 1

1

I think you can fix this by defining the logout route after the subcat route like this:

Route::get('{subcat}', array(
  'uses'  => 'frontend\homeController@uploadAd'
));

Route::get('userlogout', array(
   'uses' => 'frontend\homeController@userlogout'
));

This is happening because the first route will match any url with a single parameter. As I know the order of defining routes is important in such cases.

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

11 Comments

Its working now..I just wanna ask that what determines the routing order? Is there any specifics?
I think you mean just the opposite: the "{subcat}" is blocking "userlogout" route
The routing order is the order in which you specify the route in the routing.php file. The first matching route is the one used.
I don't think there are any specifics.. it depends from app to app.. your case is a good example when the order is important.. All I can say about this is that I would avoid using routes which could match the same url. I would create specific routes for each action. In your case I would change {subcat} to uploadAd/{subcat}
@Amarnasan The way I wrote the answer is the way the routing should be defined. If you inverse these 2 routes then the userLogout route will not work anymore because the url will be matched by the second route: {subcat}
|

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.