Laravel 7.6 Released

News

April 15th, 2020

Laravel 7.6 Released

The Laravel team released v7.6.0 yesterday with thirteen new features, along with the latest fixes and changes for the 7.x branch:

Collection “until” Method

Jason McCreary contributed a Collection::until() method that takes items in the collection until a condition is true:

// Before
[$before, $after] = $primes->partition(function ($item) {
return $item < 11;
});
$before->dump();
 
 
// Using until
$passed = $primes->until(11)->dump();

This method takes either a closure or a value to compare against the collection.

String Empty Methods

Mark van den Broek contributed a few convenience methods for Stringable and HtmlString. First, HtmlString::isEmpty() makes checking an empty instance more convenient:

$string = new \Illuminate\Support\HtmlString('');
 
// Previously
if (empty($string->toHtml()))
 
// Using isEmpty
if ($string->isEmpty())

Second, Mark contributed an isNotEmpty() convenience method to the Stringable class:

use Illuminate\Support\Stringable;
 
(new Stringable())->isNotEmpty(); // false
(new Stringable('Hello World'))->isNotEmpty(); // true

Stringable Trim Methods

Ryan Chandler contributed ltrim and rtrim methods to the Stringable class to trim characters at the beginning and end of strings:

use Illuminate\Support\Stringable;
 
echo (new Stringable(' Hello World'))->ltrim(); // 'Hello World'
echo (new Stringable('Hello World '))->rtrim(); // 'Hello World'
echo (new Stringable('/example/'))->rtrim('/'); // '/example'

Ability to Skip Middleware from Route Registration

@dsazup contributed the ability to skip middleware when defining a route:

Route::get('/something')
->skipMiddleware(VerifyCsrfToken::class)
Route::get('/teams/create')
->skipMiddleware(VerifyUserHasTeam::class)

Http Client: Get a JSON Response as an Object

Adrian Nürnberger contributed the object() method to return a JSON response body as an object instead of an associative array:

// Array access
Http::get('some-api.wip')['result'];
 
// Using json()
$response = Http::get('some-api.wip')->json();
$response['result']
 
// New option
$response = Http::get('some-api.wip')->object();
$response->result;

Component Alias Names

Dries Vints contributed setting a component alias name:

I have a use case where I want to conditionally render the contents of a component based on its alias name. For example, when you have an Svg component and use <x:heroicon-o-bell/> which is aliased to the component as follows:

Blade::component(Svg::class, 'heroicon-o-bell');

This is much cleaner than having to do <x:svg name="heroicon-o-bell"/>. Adding the alias name to the Component class will open up many new use cases and possibilities for Blade components…

Append Attributes Across an Eloquent Collection

Niels Faurskov contributed an eloquent collection append() method to append specific attributes across a collection:

// Before Laravel 7.6
$collection->each(function($model) {
$model->append($attribute)
});
 
// Append method
$collection->append($attribute);

Retry-After Method Support

@RyanDaDeng contributed method-level support that compliments a queued listener’s retryAfter property for more advanced use-cases:

// listener implementation
 
public function retryAfter()
{
// custom logic for retryAfter
}

Support for the new Composer installed.json Format

Jakub Arbet contributed the ability to support the new snapshot versions of Composer 2 (not yet stable), yet remain backward-compatible with older versions of composer:

The format of vendor/composer/installed.json was changed in the latest snapshot version of composer breaking the package discovery. This PR fixes that with backward compatibility with older versions of composer.

UUID Change Support

Mathieu Tudisco contributed support for using change() with a uuid column, which previously caused the following error:

Unknown column type “uuid” requested.

Release Notes

You can see the full list of new features and updates below and the diff between 7.5.0 and 7.6.0 on GitHub. The full release notes for Laravel 7.x are available in the latest v7 changelog:

v7.6.0

Added

  • Added Collection::until() method (#32262)
  • Added HtmlString::isEmpty() method (#32289, #32300)
  • Added Illuminate\Support\Stringable::isNotEmpty() method (#32293)
  • Added ltrim() and rtrim() methods to Illuminate\Support\Stringable class (#32288)
  • Added ability to skip a middleware (#32347, 412261c)
  • Added Illuminate\Http\Client\Response::object() method (#32341)
  • Set component alias name (#32346)
  • Added Illuminate\Database\Eloquent\Collection::append() method (#32324)
  • Added “between” clauses for BelongsToMany pivot columns (#32364)
  • Support retryAfter() method option on Queued Listeners (#32370)
  • Added support for the new composer installed.json format (#32310)
  • Added uuid change support in migrations (#32316)
  • Allowed store resource into postgresql bytea (#32319)

Fixed

  • Fixed *scan methods for phpredis (#32336)
  • Fixed Illuminate\Auth\Notifications\ResetPassword::toMail() (#32345)
  • Call setLocale in Illuminate\Translation\Translator::__construct() (1c6a504)
  • Used a map to prevent unnecessary array access in Illuminate\Http\Resources\Json\PaginatedResourceResponse::toResponse() (#32296)
  • Prevent timestamp update when pivot is not dirty (#32311)
  • Fixed CURRENT_TIMESTAMP precision bug in Illuminate\Database\Schema\Grammars\MySqlGrammar (#32298)

Changed

  • Added default value to HtmlString constructor (#32290)
  • Used BindingResolutionException to signal problem with container resolution (#32349)
  • Illuminate\Validation\Concerns\ValidatesAttributes.php ::validateUrl() use Symfony/Validator 5.0.7 regex (#32315)

Depreciated

  • Depreciate the elixir function (#32366)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.