Laravel Digest (December 2013)

Welcome to the fourth instalment of Laravel Digest, the series where I give a regular rundown of important changes, fixes and additions to Laravel’s master branch. Due to the release of Laravel 4.1 I’ve decided to bring this post forward to match the status of Laravel on the day(ish) of release. As such, below are the changes up to the middle of December 2013:

  • Collection#first can now have a closure (and default) passed to it that will be passed into a array_first-like call (d600ebe):
1
2
3
4
5
6
7
8
9
<?php

// get all users
$users = User::all();

// get first that is enabled or string 'None' if none match
$firstEnabled = $users->first(function ($key, $model) {
    return $model->enabled == 1;
}, 'None'); // obviously an awful example in terms of what it returns