URLに応じて特定のページにコンテンツを表示したい。 URLをmypage.com/menues/{city}と呼んで、特定のcitiyのレストランをすべて表示したいと思います。Laravel 5追加クエリの範囲
Route::get('menues/{city?}', '[email protected]');
そして、これのcontroler:
私はこのルートを持っている
public function scopeNowPublished($query) {
$zero = Carbon::today()->addHours(23)->addMinutes(59)->addSeconds(59);
$query->whereBetween('published_at',[Carbon::today(),$zero])->orderBy('published_at','desc');
}
QueryExceptionは上記のコードでは:私は私の記事のモデルでは、この範囲を定義し
public function menue($city = null) {
if ($city) {
$restaurants = User::with(['articles' => function ($q){
$q->nowpublished()->where('city', '=', 'Heilbronn');
}])->get();
} else {
$restaurants = User::with(['articles' => function ($q){
$q->nowpublished();
}])->get();
}
return view('pages.menues')->withRestaurants($restaurants)
->withCity($city);
}
スローされる。
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'city' in 'where clause' (SQL: select * from `articles` where `articles`.`user_id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) and `published_at` between 2016-10-06 00:00:00 and 2016-10-06 23:59:59 and `city` = Heilbronn order by `published_at` desc)
私はチェーンは残念ながら、私はこの問題を解決する方法が分からないwhere句...
で)(nowpublishedことができるかどうかわかりません。
ありがとうございました! – Mamulasa