2017-02-22 2 views
0

내가이 길을에게 전달 5 경로laravel 두 개의 매개 변수

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> 

이며,이 내가 아는이 donot 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

요 참조 배열로 매개 변수를 전달해야한다 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

감사를 사용할 수 있습니다 –