DEV Community

Morcos Gad
Morcos Gad

Posted on • Edited on

New Things Added - Laravel 8.82 Released

Let's get started quickly I found new things in Laravel 8.82 Released I wanted to share with you.

  • Cross Join Sequences in Factories

Here's the newly merged approach for joining multiple sequences

User::factory(4)
    ->state(
        new MatrixSequence(
            [['first_name' => 'Thomas'], ['first_name' => 'Agent']],
            [['last_name' => 'Anderson'], ['last_name' => 'Smith']],
        ),
    )
    ->create();

/*
[
    ['first_name' => 'Thomas', 'last_name' => 'Anderson'],
    ['first_name' => 'Thomas', 'last_name' => 'Smith'],
    ['first_name' => 'Agent', 'last_name' => 'Anderson'],
    ['first_name' => 'Agent', 'last_name' => 'Smith'],
]
*/
Enter fullscreen mode Exit fullscreen mode

Previously, you'd call sequence multiple times

User::factory(4)
    ->sequence([
        ['first_name' => 'Thomas'],
        ['first_name' => 'Thomas'],
        ['first_name' => 'Agent'],
        ['first_name' => 'Agent']
    ])
    ->sequence([
        ['last_name' => 'Anderson'],
        ['last_name' => 'Smith'],
        ['last_name' => 'Anderson'],
        ['last_name' => 'Smith'],
    ]);
Enter fullscreen mode Exit fullscreen mode

Adds a new CrossJoinSequence class that helps cross joining multiple sequences

User::factory(4)
    ->crossJoinSequence(
        [['first_name' => 'Thomas'], ['first_name' => 'Agent']],
        [['last_name' => 'Anderson'], ['last_name' => 'Smith']],
    )
    ->create();
/*
[
    ['first_name' => 'Thomas', 'last_name' => 'Anderson'],
    ['first_name' => 'Thomas', 'last_name' => 'Smith'],
    ['first_name' => 'Agent', 'last_name' => 'Anderson'],
    ['first_name' => 'Agent', 'last_name' => 'Smith'],
]
*/
Enter fullscreen mode Exit fullscreen mode
  • Transliterate String Helper

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

$value = 'ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ';
Str::transliterate($value) // abcdefghijklmnopqrstuvwxyz 
Enter fullscreen mode Exit fullscreen mode
  • Required Array Keys Validation Rule

required_array_keys validation rule which allows you to define keys that are required in an array input

$data = [
    'baz' => [
        'foo' => 'bar',
        'fee' => 'faa',
        'laa' => 'lee',
    ],
];

$rules = [
    'baz' => [
        'array',
        'required_array_keys:foo,fee',
    ],
];

$validator = new Validator($trans, $data, $rules, [], []);
$validator->passes(); // true
Enter fullscreen mode Exit fullscreen mode

Here's a failed validation attempt

$data = [
    'baz' => [
        'foo' => 'bar',
        'fee' => 'faa',
        'laa' => 'lee',
    ],
];

$rules = [
    'baz' => [
        'array',
        'required_array_keys:foo,fee,boo,bar',
    ],
];

$validator = new Validator($trans, $data, $rules, [], []);

$validator->passes(); // false

// 'The baz field must contain entries for foo, fee, boo, bar'
$validator->messages()->first('baz');
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed with me and to learn more about this release visit the sources and search more. I adore you who search for everything new.
Source :- https://laravel-news.com/laravel-8-82-0
Source :- https://www.youtube.com/watch?v=_q3gYeK7gdo

Top comments (0)