简体   繁体   English

具有相同参数但命名路径不同的URL

[英]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.

相关问题 Laravel 5中route :: controller上的参数命名 - Parameter naming on route::controller in laravel 5 是否可以在 laravel 的路由命名中使用路由参数? - Is it possible to use route parameter in route naming in laravel? 是否可以通过htaccess重定向具有相同参数和不同基本url的url - Is it possible to redirect the url with same parameter and different base url by htaccess 在Symfony中使用相同的URL但使用不同的HTTP方法和控制器操作配置路由 - Configuring a route in Symfony with the same URL but different HTTP methods and controller actions 如何使用laravel 4使用不同的控制器和相同的URL进行路由? - How to make a route with different controllers and the same URL's with laravel 4? 是否有 htaccess 规则将两个相同的 url 与其他参数不同的参数重定向到另一个相同的 url 与其他参数? - Is there htaccess rule to redirect two same url with different parameter on the other same url with other parameter? 同一模式不同的路线 - Same pattern different route 使用URL重写为同一文件传递不同的参数 - Passing Different Parameter for Same File using URL Rewrite URL的路由参数的正则表达式 - regular expression for route parameter of URL URL GET Route Laravel 中的参数 - URL Parameter in GET Route Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM