laravel 5路由传递两个参数
laravel 5 route passing two parameters
我有这条路线
Route::get('/artist/{id}/{name}', 'HomeController@artist')->where(['id' => '[0-9]+', 'name' => '[a-z]+'])->name('artist');
这是我的 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)
你必须将参数作为数组传递,参见 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]) !!}
我有这条路线
Route::get('/artist/{id}/{name}', 'HomeController@artist')->where(['id' => '[0-9]+', 'name' => '[a-z]+'])->name('artist');
这是我的 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)
你必须将参数作为数组传递,参见 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]) !!}