📜 ⬆️ ⬇️

What is new is waiting for us in Laravel 5.2.23

Laravel currently has 911 members on GitHub, many of whom are actively adding new features. Let's see what awaits us new in Laravel version 5.2.23, which is already on the threshold.
image

New in_array validation rule


The validation rules in laravel are amazing things; 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:

Validator::make( [ 'devices' => [['user_id' => 1], ['user_id' => 2]], 'users' => [['id' => 1, ['id' => 2]]] ], ['devices.*.user_id' => 'in_array:users.*.id'] ); 

Here there is a check that all the values ​​of user_id for devices correspond to the id keys from the users array.

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


Previously, callback was required as the second parameter, now it does not:
')
 $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 middleware at a time


In the controller, now when specifying a broker, you can set several at once in one line.

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

New Blade php , @endphp, and unset directives


The php directive allows you to write PHP expressions like this:

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

unset is just a wrapper for unset ().

 @unset($count) 

Ability to override basic Blade directives


Prior to version 5.2.23, it was impossible to expand Blade and override the main directives, now any of your extensions can override any directive.

New mail driver for SparkPost




New monthlyOn () method for describing scheduled tasks


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

New method app () -> isLocale ()


 //   if (app()->getLocale() == 'en') //   if (app()->isLocale('en')) 

Samples for JSON fields in MySQL 5.7 using query builder


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

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

 {"en":"name","ar":"nom"} 

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

 <image width="100" height="50"> 

You can check its availability with the following test:

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

Or check the absence of the element with the video class

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

Little known buns


Did you know that you can already do that?

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

Source: https://habr.com/ru/post/278935/


All Articles