【问题标题】:How to route with id in URL如何在 URL 中使用 id 进行路由
【发布时间】:2019-08-19 02:24:03
【问题描述】:

我想使用单击锚标记后得到的 URL accept_form/1 进行路由。

我的路线应该写什么?

我正在尝试这个:

Route::get('accept_form/{$id}', 'Controller@accept_form');

查看:

<a href="{{ url('accept_form/' . $key->id) }}" class="small-box-footer">
   More info <i class="fa fa-arrow-circle-right"></i>
</a>

【问题讨论】:

  • 分享你的代码而不是图片。
  • 堆栈溢出语法标准不允许我这样做。
  • accept_form/{$id} 应该是 accept_form/{id}

标签: php laravel laravel-routing


【解决方案1】:

为您的路线命名,

Route::get('/accept_form/{id}', 'YourController@yourMethod')->name('accept_form');

然后就可以使用了,

<a href="{{ route('accept_form', $id)}}"> More info</a> 

【讨论】:

    【解决方案2】:

    更改路线

    Route::get('accept_form/{id}', 'Controller@accept_form');
    

    锚标记

    <a href="{{ url('accept_form', $id)}}" class="small-box-footer"> More Indo </a>
    

    【讨论】:

      【解决方案3】:

      为您的路线指定一个具体名称,如下所示。

      Route::get('/accept_form/{id}', 'YourController@yourMethod')->name('accept_form');
      

      然后用数组和路由函数传递参数,

      <a href="{{ route('accept_form', [$id])}}"> More info</a> 
      

      【讨论】:

        【解决方案4】:

        你可以这样做

        {{ route('accept_form', ['id'=>$id])}}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-01-02
          • 2018-02-26
          • 1970-01-01
          • 1970-01-01
          • 2016-01-09
          相关资源
          最近更新 更多