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 19 '23 17:03

flyingL123


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 04:04

marcanuy