【问题标题】:laravel passing parameters from view to routelaravel 将参数从视图传递到路由
【发布时间】:2015-02-17 06:00:44
【问题描述】:

使用带有用户输入的视图。然后我想传递到一条路线。这是我到目前为止发现的: href="{{URL::to('customers/single'$params')}}"

我想将用户输入作为上述 $params 传递给我的路线。这是我的路线示例:

Route::get('customer/{id}', function($id) {
$customer = Customer::find($id);
return View::make('customers/single')
->with('customer', $customer);

只要我可以传递参数,我就可以对路线做我想做的事,我知道怎么做。

【问题讨论】:

  • 你到底是什么意思?您可以编辑您的问题并添加您的视图代码吗?

标签: laravel


【解决方案1】:

基本上你可以通过以下方式将参数传递给路由:

Route::get('user/{name}', function($name)
{
    //
})
->where('name', '[A-Za-z]+');

在您的锚标记中,不要执行 href={{URL...}},而是执行以下操作:

{{ URL::to('user/$param') }}

有关路由的更多信息,请访问link

【讨论】:

    【解决方案2】:

    这就是我所拥有和工作的:

        <a <button type="button"  class="buttonSmall" id="customerView"     href="{{URL::to('customer',array('id'=>'abf'))}}" >View</button></a>
    

    但我需要将数组值“abf”作为文本框的值。

    【讨论】:

      【解决方案3】:

      这在我看来锚标记对我有用

      href="{{ URL::to('user/'.$param) }}"
      

      而不是上面指定的

      href="{{ URL::to('user/$param') }}"
      

      【讨论】:

        【解决方案4】:

        您可以在我使用的视图中使用它:

        <a class="stocks_list" href="/profile/{{ Auth::user()->username }}">Profile</a>
        

        希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 2014-01-14
          • 2021-01-28
          • 2019-07-10
          • 1970-01-01
          • 2021-12-28
          • 1970-01-01
          • 2019-06-18
          • 2017-05-14
          • 1970-01-01
          相关资源
          最近更新 更多