【发布时间】:2020-04-06 14:15:12
【问题描述】:
收到我运行以下代码时发生的错误(在标题中):
SearchController.php
public function index(Request $request)
{
$distances = DB::table('posts')->select('distance')->distinct()->get()->pluck('distance');
$prices = DB::table('posts')->select('price')->distinct()->get()->pluck('price');
$post = Post::newQuery();
if ($request->has('price')) {
$post->where('price', $request->price);
}
if ($request->has('distance')) {
$post->where('distance', $request->distance);
}
return view('Pages.search', [
'distances' => $distances,
'prices' => $prices,
'posts' => $post->get()
]);
【问题讨论】:
-
它应该与
$post = Post::query()一起使用;之前没见过newQuery()方法。
标签: laravel