【问题标题】:laravel 5 route passing two parameterslaravel 5路由传递两个参数
【发布时间】:2017-02-22 04:18:41
【问题描述】:

我有这条路

Route::get('/artist/{id}/{name}', 'HomeController@artist')->where(['id' => '[0-9]+', 'name' => '[a-z]+'])->name('artist');

这是我的链接

<a href="{{route('artist',$artist->id,$artist->name)}}">{{$artist->name}}</a>

这是 HomeController 上的艺术家方法

public function artist($id, $name){ $artist = Artist::where('id', $id)->where('name', $name)->first();

    return view('front.artist', compact('artist'));
}

我不知道这个显示错误。这是错误。所以请任何人帮助我。我正在学习 laravel。

ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: artist] [URI: artist/{id}/{name}]. (View: C:\xampp\htdocs\laravel\resources\views\front\home.blade.php)

【问题讨论】:

    标签: php laravel-5.4


    【解决方案1】:

    你必须将参数作为数组传递,见https://laravel.com/docs/5.4/helpers#method-route

    route('artist',['id' =&gt; $artist-&gt;id, 'name' =&gt; $artist-&gt;name])

    或者你可以使用

    {!! link_to_route('artist', $artist-&gt;name, ['id' =&gt; $artist-&gt;id, 'name' =&gt; $artist-&gt;name]) !!}

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 2017-01-12
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 2019-03-03
      • 2018-08-14
      • 2019-08-07
      • 2020-01-23
      相关资源
      最近更新 更多