2017-02-22 154 views
0

我有这个路线laravel 5路线传递两个参数

Route::get('/artist/{id}/{name}', '[email protected]')->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')); 
} 

艺术家方法我DONOT知道此显示错误。这是错误。所以请任何人帮助我。我正在学习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

呦必须通过参数数组,见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]) !!}

+0

感谢它为我工作 –