What’s new in Laravel 7.x?

Tram Ho

Only a few weeks from the release of Laravel 7, so I’ve gathered a list of some important new features and changes. Of course this is not all but it is a brief overview of some new content.

Add “subquery value” in the where statement

Let’s say you have an olympics app that keeps track of all the athletes and their medals. Let’s say you want to find all athletes whose latest medal is the gold medal. Here’s how you can do it with this new feature:

Previously the where method with the first parameter was a column in the table, now it could be a subquery (a column of another table is linked).

Add Collection :: sortDesc ()

Laravel currently has only sort but doesn’t have sortDesc so this is a new method, the way it works like sort () is just the inverse.

Add HandleCors middleware

There will be a new default middleware called HandleCors that uses the default package https://github.com/fruitcake/laravel-cors to allow you to send Cross-Origin Resource Sharing headers.

Allow Collection :: push to receive multiple input values

Currently the push collection only accepts 1 input value, 7x version will receive more than 1

Customize Cast Types

Currently with $ casts only use the predefined types, version 7x you can customize it as you like. Object cast must implements Illuminate Contracts Database Eloquent CastsAttributes is the contract of CastsInboundAttributes

No longer supports Monolog v1

Simply Monolog v2 then should k support again

It is easier to customize RouteKeyName in Route Model Binding

If you know the Route Model Binding feature in Laravel, the model will automatically bind to the controller based on parameters

When you want to bind by id, sometimes you need to bind by slug, then you have to customize the model with equal

In this version 7x will be easier

Released the Laravel Airlock package

Laravel Airlock is a new official package developed by Laravel.

Laravel Airlock provides an extremely lightweight authentication system for SPA websites and simple API.

The reason for launching Airlock:

  1. Solutions for SPA Authentication are now trying to store user tokens under local, which means that the XSS vulnerability is ready to wait and read them.
  2. If you use Passport and you only use it for authentication, it is no different from using buffalo scalpel to kill chickens.
  3. If the Passport is too heavy, one would think of a smaller package to solve this problem which is JWT, by simply providing a token to a third party, and it is completely separate and has nothing to do it with OAuth.

If you are building a SPA Laravel website, you should consider using this package. The time of posting is still too early to publicize, but introduce beforehand for you to find out.


Multiple Mailers

Currently Laravel has multi database, multi log, multi session, multi broadcast, … just doesn’t have multi mailers.

The mailer is singleton in the container, so no matter if you change the mailer change, the custom must be very tiring .. so it can be said that this feature is very useful.

The configuration of multi mailers will be in the mail.php config file in version 7x

The default auth will return API style when receiving XHR Requests

This updates the built-in authentication to return a 2xx response when normal (or 4xx when validated) on XHR requests instead of returning redirects and session operations, etc.

Upgrade to Symfony 5

Laravel only uses new items, so there’s nothing to discuss.


Share the news now

Source : Viblo