2016-11-26 5 views
3

私のコントローラにこの機能があります。Laravelクエリビルダはgetメソッドの変数を使用していません

public function tourList($country, $category) 
{ 
    $tour = Tour::whereHas('country', function($q) { 
        $q->where('name','=', $country); 
       }) 
       ->whereHas('category', function($r) { 
        $r->where('name','=', $category); 
       }) 
       ->get(); 

    return view('tour-list.blade.php')->withTour('$tour'); 
} 

getメソッドから2つの変数を渡しましたが、しかし、私はあなたのクエリのようになりwilllので、あなたは匿名関数でuseが欠落している

Undefined variable: country 
+0

くれ – PassionInfinite

+0

ルート@zacharyDaleルート・パスを表示::取得( 'tour/{country}/{categpry}'、['as' => 'tour.list'、 'uses' => 'PublicController @ tourList']); –

+0

これは私のルートです –

答えて

3

のエラーを取得しています:

$tour = Tour::whereHas('country', function($q) use($country) { 
       $q->where('name','=', $country); 
      }) 
      ->whereHas('category', function($r) use($category) { 
       $r->where('name','=', $category); 
      }) 
      ->get(); 

Docs