我有这条路线
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)
答案 0 :(得分:0)
哟必须将参数作为数组传递,请参阅https://laravel.com/docs/5.4/helpers#method-route
route('artist',['id' => $artist->id, 'name' => $artist->name])
或者您可以使用
{!! link_to_route('artist', $artist->name, ['id' => $artist->id, 'name' => $artist->name]) !!}