Laravel5.2.23 New Feature Preview

Source: Internet
Author: User
Laravel5.2.23 new feature preview by the time this article was published, Laravel has already had 911 contributors on Github, and some of them are helping the framework add something better on a daily basis. The following summarizes some new features that will be added to Laravel 5.2.23.

1. in_array () validation rules

Array validation in Laravel is very good. recently I replaced a lot of code in my project, just a few lines of code. Add a new rule in 5.2.23 to verify whether the value of a key is in another related key.

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

This code ensures that all user_id values are in users.

2. Arr: first () & Arr: last () provides optional callback functions.

In the previous version, the callback function is required as the second parameter and will become an optional parameter in 5.2.23.

$array = [100, 200, 300];// (NEW) This will return 100Arr::first($array); /** same for **/ array_first($array);// (NEW) This will return 300Arr::last($array); /** same for **/ array_last($array);// (You still can) do this and return 200Arr::first($array, function ($key, $value) {    return $value >= 150;});
3. specify multiple middleware at a time

When adding middleware to the controller, you can register multiple middleware in one statement.

$this->middleware(['auth', 'subscribed'], ['only' => ['getCandy']]);
4. new commands @ php, @ endphp, and @ unset are added to the Blade.

@ Php command allows you to write PHP statements like this:

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

@ Unset () is actually an encapsulation of unset:

@unset($count)
5. ability to rewrite core Blade commands

Before 5.2.23, you could not extend Blade or rewrite core commands, but now you can rewrite any core commands.

6. avoid compiling Blade commands

Now you can add a @ symbol before the Blade command to avoid compiling the command.

// output: 
 @continue// output: @continue@@continue
7. new email driver for SparkPost 8. new scheduling command monthlyOn ()
$schedule->call(function () {    DB::table('shopping_list')->delete();})->monthlyOn(4, '12:00');
9. new app ()-> isLocale () method
// Instead of thisif (app()->getLocale() == 'en')// You can do thatif (app()->isLocale('en'))
10. use the query builder to query MySQL 5.7 to generate JSON fields more smoothly

After MySQL 5.7 is released, a new JSON field is introduced. in Laravel 5.2.23, you can quickly query Json fields as before.

Assume that our users table has a name column of the JSON type, which has the following value:

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

You can use the following syntax to query the value:

User::where('name->en', 'name')->get();// You may pe deep in the JSON string using the `->` operator.User::where('contacts->phone->home', 1234);
11. test the auxiliary methods seeElement () and dontSeeElement ()

Suppose there are the following elements:

 

You can use the following test method:

$this->seeElement('image', ['width' => 100, 'height' => 50]);$this->dontSeeElement('image', ['class' => 'video']);
12. hide benefits #1

Do you know you can 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();
13. hide benefits #2
// Instead of this:if(!$item){    abort(404);}// You can do that:abort_unless($item);// You may also have something like this:abort_if($item->is_hidden);

Translated from: themsaid. For more information, see Specs Blog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.