alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Method Illuminate\\\\Support\\\\Collection::latest does not exist in laravel ?

Method Illuminate\\\\Support\\\\Collection::latest does not exist in laravel ?

latest() is an Eloquent method for queries that essentially asks the database to orderBy('created_at', 'desc').

Unfortunately, this method does not exist on the Laravel collection (thus the error message).

You can, however, make this work the way you want, using a different method on your collection.

Try:

 return collect($this->messages)->sortBy('created_at'); 

You can get pretty crafty with sortBy, creating virtually anything you want using a closure:

 $x = $collection->sortBy(function ($product, $key) {
    return count($product['colors']);
}); 

The base method also takes a variety of standard PHP sort flags to make life easy. E.g.:

 $collection->sortBy('title', SORT_NATURAL);

12 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online