【问题标题】:Laravel route link with parameter not work带有参数的Laravel路由链接不起作用
【发布时间】:2016-05-23 04:32:43
【问题描述】:

在我的路线中有可选参数。当我点击我的链接然后它的创建问题。它看起来像

http://localhost/my/public/admin/category/sub-create?2

但它会是

http://localhost/my/public/admin/category/sub-create/2

我的路线

     Route::get('sub-create/{cid?}',['as'=>'new_sub_category',
'uses'=>'CategoryController@SubCategoryCreate']);

我的链接

<a href="{{route('new_sub_category', $categoryID)}}"
     class="btn bg-navy btn-flat margin">
    <i class="fa fa-plus-square"></i> Add New Subcategory</a>

【问题讨论】:

  • 你使用的是什么版本的 laravel,我只是在 tinker 中复制了你的路线,没有任何问题。 $ php artisan tinker Psy Shell v0.6.1 (PHP 5.6.5 — cli) by Justin Hileman >>> Route::get('sub-create/{cid?}',['as'=>'new_sub_category', . .. 'uses'=>'CategoryController@SubCategoryCreate']); => Illuminate\Routing\Route {#1026} >>> route('new_sub_category', 2); => "localhost/sub-create/2" >>>
  • 版本 5.2 @LoganBailey
  • 是的,我无法通过全新的 laravel 安装来复制它。也许发布您的php artisan route:list 或验证$categoryId 没有问题。
  • 您能否确认您看到的是顶部结果并且您想要底部结果?还是您想要最高结果而您看到的是最低结果?

标签: php laravel laravel-5 laravel-routing laravel-5.2


【解决方案1】:

沿着这条路走。这将创建正确的路线

{{route('new_sub_category', ['cid'=>$categoryID])}}

<a href="{{route('new_sub_category', ['cid'=>$categoryID])}}"
     class="btn bg-navy btn-flat margin">
    <i class="fa fa-plus-square"></i> Add New Subcategory</a>

【讨论】:

    猜你喜欢
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 2019-09-19
    • 2018-09-23
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    相关资源
    最近更新 更多