hu7sy
hu7sy

Reputation: 961

URL with same parameter , but with different Naming route

i have two URL'S one is

Route::get(
        '/{cat}/{slug}',
        [
            'uses' => 'User\UserEndController@category',
            'as'=>'showCategory',
            'middleware'=>'web'
        ]
    );

and other one is this

Route::get(
        '/{mostParentCat}/{performerSlug}',
        [
            'uses' => 'User\UserEndController@performerWithoutParent',
            'as'=>'performerWithoutParent',
            'middleware'=>'web'
        ]
    );

both of them get two parameters after slash i have to redirect them to different functions. i know that's not a good way to use same routes but that's a client requirement

Upvotes: 0

Views: 33

Answers (1)

Francesco Malatesta
Francesco Malatesta

Reputation: 679

If this is a client requirement and you can't do nothing else, I would create a single route

'/{cat}/{slug}'

and link it to an action which responsibility is to check what kind of behaviour you need.

Once you understand what do you need, you could use two different classes (one for the '/{cat}/{slug}' combination, and one for the /{mostParentCat}/{performerSlug}).

Take a look, also, to the strategy design pattern. It could help you.

Hope it helps :)

Upvotes: 0

Related Questions