amrfs
amrfs

Reputation: 1

Binding routes to wrong method controller

I am using laravel 5.1 app. I have the bellow routes:

Route::get('{thing}', 'DisplayController@showThingNewRoute');
Route::get('{about}', 'DisplayController@showAboutNewRoute');

Also I use RouteServiceProvider like so:

    public function boot(Router $router)
    {

    parent::boot($router);

    $router->bind('thing', function($thing){ 
       return \App\Thing::publish()->where('seo_url', '=', $thing)->first(); 
   }); 

    $router->bind('about', function($about){ 
       return \App\About::publish()->where('seo_url', '=', $about)->firstOrFail(); 
    });    

    }

The problem is that I can't have a route to execute with a second method showAboutNewRoute

What am i doing wrong here?

Upvotes: 0

Views: 67

Answers (2)

EkinOf
EkinOf

Reputation: 451

Your routes have the same URL, the access conditions are the same. For laravel if you put one string next to the root URL you access both of the routes.

You need to disambiguate the routes like this for example :

Route::get('thing/{thing}', 'DisplayController@showThingNewRoute');
Route::get('about/{about}', 'DisplayController@showAboutNewRoute');

Upvotes: 0

Vikash
Vikash

Reputation: 3561

Your both route share the same url, whatever you are putting inside curly braces it is like a variable.

You can define your route like this

Route::get('thing/{thing}', 'DisplayController@showThingNewRoute');
Route::get('about/{about}', 'DisplayController@showAboutNewRoute');

Otherwise whatever you will put after your domain, it will pick as first route unless you define any string as a first argument of get method.

Upvotes: 2

Related Questions