5.7.13 was Wednesday with some new collection methods and the ability to return an array of messages in a custom validation rule.

First, new empty collection methods were added, including whenEmpty, whenNotEmpty, unlessEmpty, and unlessNotEmpty. For example, the whenEmpty method will fire this callback on an empty collection:

<?php

use IlluminateSupportCollection;

$collection = new Collection;

$collection->whenEmpty(function ($collection) {
    return $collection->push('adam');
});

$this->assertSame(['adam'], $collection->toArray());

The unless* behave the opposite way:

<?php

use IlluminateSupportCollection;

$collection = new Collection;

$collection->unlessEmpty(function ($collection) {
    return $collection->push('adam');
});

$this->assertSame([], $collection->toArray());

If the collection isn’t empty, the unlessEmpty closure is called:

<?php

use IlluminateSupportCollection;

$collection = new Collection(['user1', 'user2']);

$collection->unlessEmpty(function ($collection) {
    return $collection->push('user3');
});

$this->assertSame(['user1', 'user2, 'user3'], $collection->toArray());

Next, the ability to add an array of validation messages to custom validation rules was added. In a custom validation rule, you can return an array of messages like so:

public function message()
{
    return [
        ':attribute must be taylor',
        ':attribute must be a first name'
    ];
}

You can see the full diff between 5.7.12 and 5.7.13 on GitHub, and the full release notes below from the 5.7 changelog.

v5.7.13

Added

  • Added ability to return an array of messages in a custom validation rule (#26327)
  • Added whenEmpty/ whenNotEmpty / unlessEmpty / unlessNotEmpty methods to Collection (#26345)
  • Added IlluminateSupportCollection::some method (#26376, 8f7e647)
  • Added IlluminateCacheRepository::missing method (#26351)
  • Added Macroable trait to IlluminateViewFactory (#26361)
  • Added support for UNION aggregate queries (#26365)

Changed

  • Updated AbstractPaginator::appends to handle null (#26326)
  • Added “guzzlehttp/guzzle”: “^6.3”, to composer.json (#26328)
  • Showed exception message on 403 error page when message is available (#26356)
  • Don’t run TransformsRequest twice on ?query= parameters (#26366)
  • Added missing logging options to slack log driver (#26360)
  • Use cascade when truncating table in PostgreSQL (#26389)
  • Allowed pass absolute parameter in has valid signature request macro (#26397)

Changed realization

  • Used Request::validate macro in Auth traits (#26314)



Source link https://laravel-.com/laravel-5-7-13

LEAVE A REPLY

Please enter your comment!
Please enter your name here