dousao8152
dousao8152
2017-02-22 04:18

laravel 5路由传递两个参数

已采纳

i have this route

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>

and this is the artist method on HomeController

public function artist($id, $name){ $artist = Artist::where('id', $id)->where('name', $name)->first();

    return view('front.artist', compact('artist'));
}

i donot know this display error. this is the error. so please any one help me with this. iam in the middle of learning laravel.

ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: artist] [URI: artist/{id}/{name}]. (View: C:\xampp\htdocs\laravelesources\views\front\home.blade.php)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dream_life5200 dream_life5200 4年前

    Yo must pass the parameters as array, see https://laravel.com/docs/5.4/helpers#method-route

    route('artist',['id' => $artist->id, 'name' => $artist->name])

    or you can use

    {!! link_to_route('artist', $artist->name, ['id' => $artist->id, 'name' => $artist->name]) !!}

    点赞 评论 复制链接分享

为你推荐