11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Eloquent Queries 290<br />

32 title: "...Anywhere But Here",<br />

33 artist: "The Ataris",<br />

34 genre: "Punk Rock",<br />

35 year: 1997<br />

36 },<br />

37 {<br />

38 id: 6,<br />

39 title: "...Is A Real Boy",<br />

40 artist: "Say Anything",<br />

41 genre: "Indie Rock",<br />

42 year: 2006<br />

43 }<br />

44 ]<br />

First<br />

In circumstances where a collection of model instances will normally be returned, the first() fetch<br />

method can be used to retrieve the first model instance stored within. It’s very useful if you would<br />

rather that a query return a single instance, rather than a collection of model instances. Without a<br />

constraint, first() will simply return the first row in the database table.<br />

Here’s an example.<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!