What's new awaits us in Laravel 5.2.23

Original author: Mohamed Said
  • Transfer
Currently, Laravel already has 911 members on GitHub, many of them are actively adding new functionality. Let's see what awaits us new to Laravel version 5.2.23, which is already on the verge.

New in_array validation rule

The validation rules in laravel are just an amazing thing, I personally replaced a bunch of code in some projects with a couple of validation lines.
In 5.2.23 a new rule is added. It helps to verify that the value of an array element is contained in another array:

        'devices' => [['user_id' => 1], ['user_id' => 2]],
        'users' => [['id' => 1, ['id' => 2]]]
    ['devices.*.user_id' => 'in_array:users.*.id']

This verifies that all user_id values ​​on devices match the id keys in the users array.

Arr :: first () & Arr :: last () callback is now optional

Earlier, a callback was required as a second parameter, now no:

$array = [100, 200, 300];
// По НОВОМУ  Этот код вернет 100
Arr::first($array); /** тоже самое что и  **/ array_first($array);
// По НОВОМУ  Этот код вернет 300
Arr::last($array); /**тоже самое что и  **/ array_last($array);
// Можно и (как РАНЬШЕ)  сделать это и получить 200
Arr::first($array, function ($key, $value) {
    return $value >= 150;

Specifying more than one intermediary (middleware) at a time

In the controller, now when specifying an intermediary, you can specify several at once with one line.

$this->middleware(['auth', 'subscribed'], ['only' => ['getCandy']]);

New Blade php , @endphp, and unset directives

The php directive will allow you to write PHP expressions this way:

@php($count = 1)
@php(++ $count)
$now = new DateTime();
$environment = isset($env) ? $env : "testing";

unset is just a wrapper for unset ().


Ability to override basic Blade directives

Prior to version 5.2.23, it was impossible to extend Blade and redefine basic directives, now any extension you can override any directive.

New mail driver for SparkPost

New monthlyOn () method for describing scheduled tasks

$schedule->call(function () {
})->monthlyOn(4, '12:00');

New app () -> isLocale () method

// Вместо этого
if (app()->getLocale() == 'en')
// можно сделать
if (app()->isLocale('en'))

Fetching JSON fields in MySQL 5.7 using the query builder

In MySQL 5.7, a new column type appeared - JSON. In Laravel 5.2.23, you can make selections on these fields as freely as usual.

Imagine that we have a users table with a name column of type JSON, the field contains values ​​of the type:


Now you can make a similar condition

User::where('name->en', 'name')->get();
// Углубиться в структуру JSON можно при  помощи оператора `->`.
User::where('contacts->phone->home', 1234);

New methods for testing seeElement () and dontSeeElement ()

If the page has such an element

You can check for its presence using this test:

$this->seeElement('image', ['width' => 100, 'height' => 50]);

Or check the absence of an element with class video

$this->dontSeeElement('image', ['class' => 'video']);

Little-known buns

Did you know that you can already do this?

User::whereNameAndEmail('jon', 'jon@theWall.com')->first();
User::whereNameAndEmailOrPhone('jon', 'jon@theWall.com', '123321')->first();
DB::table('users')->whereEmailOrUsername('mail@mail.com', 'themsaid')->first();

Also popular now: