php - Method orderBy does not exist in Laravel Eloquent? -


i have piece of code this:

$products = product::all()  if ($search_value) {     $products = $products->where('name', 'like', "%$search_value%"); }  $products = $products->orderby('created_at', 'desc')->skip(10)->take(10)->with('tags')->get(); 

i got following error:

badmethodcallexception in macroable.php line 81: method orderby not exist. 

i guess orderby need follow product:: directly, can't save $products = product::, can i?

any suggestions? thanks.

you're trying use orderby() method on eloquent collection. try use sortbydesc() instead.

alternatively, change $products = product::all(); $products = new product();. code work expect.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -