Laravel 5路由传递两个参数

3
我有这个路由。
Route::get('/artist/{id}/{name}', 'HomeController@artist')->where(['id' => '[0-9]+', 'name' => '[a-z]+'])->name('artist');

and this is my link

<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)
1个回答

3
您必须以数组形式传递参数,请参见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]) !!}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接