【问题标题】:Get multiple ids from a slug Laravel 4从蛞蝓 Laravel 4 中获取多个 id
【发布时间】:2015-11-18 10:44:30
【问题描述】:

当我将旧网站迁移到 laravel 时,我想实现如下所示的网址,但需要制作与以前相同的网址。

http://example.com/garage-stalls-plans-plan10-4245

我做了什么来生成这样的网址:

<a href="{{ $title.'-'.'plan'.$id1.'-'.$id2}}">Link</a>

它工作正常,但如何在详细信息页面控制器中获取 $id 和 $id2 值?

这是我的路线

    Route::get('{title}-{id1}-{id2}', 'SearchController@details')
        ->where('title', '.*?')
        ->where('id1', '[0-9]')
->where('id2', '\d+')
;

需要在控制器中获取 10 和 4245。如果我删除第二个 where '->where('id1', '[0-9]')' 我会完美地得到 plan10 和 4245。如果我想要 10 和 4245 怎么办?

类似的东西 Get the id from a slug Laravel 4

【问题讨论】:

    标签: php laravel laravel-4 parameter-passing laravel-routing


    【解决方案1】:
    Route::get('{slug}{id1}-{id2}', 'SearchController@details')
    ->where('slug', '[a-Z\-]+')
    ->where('id1', '[0-9]+')
    ->where('id2', '[0-9]+');
    

    试试类似的方法

    【讨论】:

    • 'awesome-product' 正在动态生成。
    • 不工作。 Route::get('{title}-{id1}-{id2}', 'SearchController@details') ->where('title', '.*?') ->where('id1', '^[ 0-9]*$') ->where('id2', '\d+') ;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 2015-08-27
    • 2016-07-27
    相关资源
    最近更新 更多