Updated 6 March 2020
Recently, Laravel released it’s 7th version of the framework officially on 3rd March 2020. Although it isn’t the LTS update but it brings a lot of new cool features and previous fixes. It is one major update according to the Laravel’s version support and update policy. This update will provide the bug fixes for the next 6 months ( September 3, 2020 ) and 1 year security fixes ( March 3, 2021).
The new features arrived with the Laravel 7 are:
1. Laravel Airlock
2. Zttp for Http Client
3. CORS Support
4. Fluent String Operations
5. Custom Eloquent Cast
6. Blade X
7. Customizable Stubs
8. Query Time Casts
9. Multiple Mail driver
10. New artisan Commands
Laravel Airlock is a new package which provides a featherweight authentication system for single page applications, mobile applications, and simple, token based APIs. with the Airlock package a user of your application is allowed to generate multiple API tokens for their account. These tokens are able to grant abilities / scopes which specify which actions the tokens are allowed to perform.
Zttp is a simple Guzzle wrapper designed to provide a really pleasant development experience for most common use cases. It is a new PHP package by Adam Wathan that is a Guzzle wrapper designed to bring an expressive syntax and simplify common use cases.
I already explained about Zttp in my previous blog. You can check it out from here:
What is ZTTP and How to use it
CORS support was contributed by Barry vd. Heuvel.
Laravel can automatically respond to CORS OPTION requests with values that you configure. All CORS settings may be configured in your CORS configuration file and OPTIONS requests will automatically be handled by the HandleCors middleware that is included by default in your global middleware stack.
Laravel 7 now offers a more object-oriented, fluent string manipulation library built on top of these functions. Previously, llluminate\Support\str class was there, which provides a variety of helpful string manipulation functions.
But Now, you can create a fluent llluminate\Support\Striangable object using the Str::of method. A variety of methods may then be chained onto the object to manipulate the string:
1 2 3 4 |
return (string) Str::of(' Laravel Framework 6.x ') ->trim() ->replace('6.x', '7.x') ->slug(); |
Classes that implement this interface must define a get and set methods. The get method is responsible for transforming a raw value from the database into a cast value, while the set method should transform a cast value into a raw value that can be stored in the database. As an example, we will re-implement the built-in json cast type as a custom cast type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class Json implements CastsAttributes { /** * Cast the given value. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param mixed $value * @param array $attributes * @return array */ public function get($model, $key, $value, $attributes) { return json_decode($value, true); } /** * Prepare the given value for storage. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $key * @param array $value * @param array $attributes * @return string */ public function set($model, $key, $value, $attributes) { return json_encode($value); } } |
Laravel 7 brought to you the all new first party feature of Blade X package. This package provides an easy way to render custom HTML components in your Blade views.
Previously, you were supposed to write like this:
1 |
@include('myAlert', ['type' => 'error', 'message' => $message]) |
But, Now with the blade-X you can write it like this:
1 |
<my-alert type="error" :message="$message" /> |
In order to customize stub files, you need to publish them:
1 |
php artisan stub:publish |
After running this command, a new directory will be added in your project.
Query time casting was contributed by Matt Barlow.
Sometimes you may need to apply casts while executing a query, such as when selecting a raw value from a table. For example, consider the following query:
1 2 3 4 5 6 7 8 |
use App\Post; use App\User; $users = User::select([ 'users.*', 'last_posted_at' => Post::selectRaw('MAX(created_at)') ->whereColumn('user_id', 'users.id') ])->get(); |
The last_posted_at attribute on the results of this query will be a raw string. It would be convenient if we could apply a date cast to this attribute when executing the query. To accomplish this, we may use the withCasts method provided by Laravel 7:
1 2 3 4 5 6 7 |
$users = User::select([ 'users.*', 'last_posted_at' => Post::selectRaw('MAX(created_at)') ->whereColumn('user_id', 'users.id') ])->withCasts([ 'last_posted_at' => 'date' ])->get(); |
Laravel 7 allows the configuration of multiple “mailers” for a single application. Each mailer configured within the mail configuration file may have its own options and even its own unique “transport”, allowing your application to use different email services to send certain email messages.
Source:
Laravel 7
Laravel 6
What is Zttp
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments