首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >不应静态调用非静态方法Illuminate\Database\Eloquent\Model::newQuery()

不应静态调用非静态方法Illuminate\Database\Eloquent\Model::newQuery()
EN

Stack Overflow用户
提问于 2020-04-06 14:15:13
回答 1查看 194关注 0票数 1

每当我运行以下代码时,都会收到错误(在标题中):

SearchController.php

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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()
   ]);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-06 14:18:16

使用

query();

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 $post = Post::query();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61061858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文