【发布时间】:2017-04-10 18:07:42
【问题描述】:
我的一个控制器中有这个功能。
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 方法中传递了两个变量。但我得到了错误
Undefined variable: country
【问题讨论】:
-
显示路线路径@zacharyDale
-
Route::get('tour/{country}/{categpry}', ['as' => 'tour.list', 'uses' => 'PublicController@tourList']);
-
将 '$tour' 更改为 $tour,因为我们必须在 withTour 中传递变量。
标签: php laravel-5.3 laravel-query-builder