Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Eloquent ORM returning collection with single item

Using Laravel 4.2 and eloquent ORM, I know that all multi-result sets returned by a query will return a Collection object, as documented here (http://laravel.com/docs/eloquent#collections).

I am running a query that returns a single object:

$faq = ProductFaq::where($where)->with('products')->get();

However, I'm being returned a collection.

In order to use the result do I need to chain ->first() to the end of my statement? I'm just confused if the docs are saying that every call that uses get() will return a collection, or only get() calls that have multiple results.

like image 994
flyingL123 Avatar asked Mar 20 '23 00:03


1 Answers

Get returns a Collection instance, you should call first instead of the get method

 $faq = ProductFaq::where($where)->with('products')->first();
like image 51
marcanuy Avatar answered Apr 02 '23 11:04