KaranjitFYP
KaranjitFYP

Reputation: 103

Non-static method Illuminate\Database\Eloquent\Model::newQuery() should not be called statically

Receiving the error (in title) that happens whenever i run the following code:

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()
   ]);

Upvotes: 1

Views: 650

Answers (1)

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Use

query();

 $post = Post::query();

Upvotes: 2

Related Questions