[英]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 我知道这不是使用相同路线的好方法,但这是客户的要求
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}
). 一旦了解了您的需求, 就可以使用两种不同的类 (一种用于'/{cat}/{slug}'
组合,另一种用于/{mostParentCat}/{performerSlug}
)。
Take a look, also, to the strategy design pattern . 也看一下策略设计模式 。 It could help you. 它可以帮助您。
Hope it helps :) 希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.