Laravel: How does the query builder handle ->first()?

The first() method will always return one result or null if no results are found. Here's all it does:
public function first($columns = array('*'))
{
    $results = $this->take(1)->get($columns);

    return count($results) > 0 ? reset($results) : null;
}
The difference to just using take(1) (or limit(1)) is that it actually just returns one result object, by calling reset(). (Also, first() obviously executes the query. The others don't)

Comments

Popular posts from this blog

How can I debug PHP cURL sessions?

Free icons

Where is the security section of google analytics? “Security Issues” section.