Laravel 8.82 Released

News

February 2nd, 2022

laravel8.jpg

The Laravel team released 8.82 with factory matrix sequences, a transliterate string helper, a new validation rule, and more:

Cross Join Sequences in Factories

@thomasowow contributed a new method and class that helps join multiple factory sequences.

Here's the newly merged approach for joining multiple sequences:

1User::factory(4)
2 ->state(
3 new MatrixSequence(
4 [['first_name' => 'Thomas'], ['first_name' => 'Agent']],
5 [['last_name' => 'Anderson'], ['last_name' => 'Smith']],
6 ),
7 )
8 ->create();
9 
10/* Results in:
11[
12 ['first_name' => 'Thomas', 'last_name' => 'Anderson'],
13 ['first_name' => 'Thomas', 'last_name' => 'Smith'],
14 ['first_name' => 'Agent', 'last_name' => 'Anderson'],
15 ['first_name' => 'Agent', 'last_name' => 'Smith'],
16]
17*/

Previously, you'd call sequence multiple times:

1User::factory(4)
2 ->sequence([
3 ['first_name' => 'Thomas'],
4 ['first_name' => 'Thomas'],
5 ['first_name' => 'Agent'],
6 ['first_name' => 'Agent']
7 ])
8 ->sequence([
9 ['last_name' => 'Anderson'],
10 ['last_name' => 'Smith'],
11 ['last_name' => 'Anderson'],
12 ['last_name' => 'Smith'],
13 ]);

Check out Pull Request #40542 for more examples and implementation details. You can learn more about sequences in the Database Testing documentation.

Transliterate String Helper

Liam Hackett contributed a Str::transliterate() method which transliterates a string to its closes ASCII representation:

1$value = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
2$this->assertSame(
3 'abcdefghijklmnopqrstuvwxyz',
4 Str::transliterate($value)
5);

If you're interested in what prompted this addition, read the discussion on Pull Request #40681.

Required Array Keys Validation Rule

Andrew Arscott contributed a required_array_keys validation rule which allows you to define keys that are required in an array input:

1$data = [
2 'baz' => [
3 'foo' => 'bar',
4 'fee' => 'faa',
5 'laa' => 'lee',
6 ],
7];
8 
9$rules = [
10 'baz' => [
11 'array',
12 'required_array_keys:foo,fee',
13 ],
14];
15 
16$validator = new Validator($trans, $data, $rules, [], []);
17$validator->passes(); // true

Here's a failed validation attempt:

1 
2$data = [
3 'baz' => [
4 'foo' => 'bar',
5 'fee' => 'faa',
6 'laa' => 'lee',
7 ],
8];
9 
10$rules = [
11 'baz' => [
12 'array',
13 'required_array_keys:foo,fee,boo,bar',
14 ],
15];
16 
17$validator = new Validator($trans, $data, $rules, [], []);
18 
19$validator->passes(); // false
20 
21// 'The baz field must contain entries for foo, fee, boo, bar'
22$validator->messages()->first('baz');

Release Notes

You can see the complete list of new features and updates below and the diff between 8.81.0 and 8.82.0 on GitHub. The following release notes are directly from the changelog:

v8.82.0

Added

  • Added class and method to create cross joined sequences for factories (#40542)
  • Added Transliterate shortcut to the Str helper (#40681)
  • Added array_keys validation rule (#40720)

Fixed

  • Prevent job serialization error in Queue (#40625)
  • Fixed autoresolving model name from factory (#40616)
  • Fixed : strtotime Epoch doesn't fit in PHP int (#40690)
  • Fixed Stringable ucsplit (#40694, #40699)

Changed

  • Server command: Allow xdebug auto-connect to listener feature (#40673)
  • respect null driver in QueueServiceProvider (9435827, 56d433a)
  • Allow to push and prepend config values on new keys (#40723)

Filed in:

Paul Redmond

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

Laravel News Partners