【问题标题】:Non-static method Illuminate\Database\Eloquent\Model::newQuery() should not be called statically不应静态调用非静态方法 Illuminate\Database\Eloquent\Model::newQuery()
【发布时间】: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


【解决方案1】:

使用

query();

 $post = Post::query();

【讨论】:

  • 太棒了,所以我已经做到了,现在我按提交,没有出现任何内容并且功能不起作用
  • 如果此答案对您有帮助,请标记为已验证@codingkid
  • 请更改您的提交事件。
猜你喜欢
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-16
  • 2014-09-08
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多