What Is New In Laravel 7 ? List Of All New Features
Let’s check all the new features that will be available in Laravel 7,
Better routing speed
Blade component tags
Fluent string operations
New artisan commands
A new HTTP client
Multiple Mail driver
CORS support
Better routing speed
This Laravel 7 release is with better routing speed and it will give 2x faster speed than earlier version using route:cache. Using the Route Model, You can bind your Model in your route and this is one of the best features.
Route::get('users/{user:slug}', function (App\User $user) {
return $user;
});
Route::get('users/{user:slug}', function (App\User $user) { return $user; });
Blade Component Tags
This release of Laravel 7 allows you to define your own components and you can use them in your blade files as below,
Define Component
<?php namespace App\View\Components; use Illuminate\View\Component; class Alert extends Component { public $type; public $message; public function __construct($type, $message) { $this->type = $type; $this->message = $message; } public function render() { return view('components.alert'); } }
<?php namespace App\View\Components; use Illuminate\View\Component; class Alert extends Component { public $type; public $message; public function __construct($type, $message) { $this->type = $type; $this->message = $message; } public function render() { return view('components.alert'); } }
Component Tag
<div class="notify {{ $classForType() }}">
{{ $heading }}{{ $slot }}
</div>
<div class="notify {{ $classForType() }}"> {{ $heading }}{{ $slot }} </div>
Using it in Blade files
<x-notify type="error" class="mb-4">
<x-slot name="heading">
Alert content...
</x-slot>
Default slot content...
<x-notify>
<x-notify type="error" class="mb-4"> <x-slot name="heading"> Alert content... </x-slot> Default slot content... <x-notify>
Fluent String Operations
This fluent String Operations were developed by Taylor Otwell.
In earlier versions of Laravel there is an existing Illuminate\Support\Str class available to help for string manipulation functions. Now Laravel 7 offers a more object oriented and fluent string manipulation library built on top of these functions and it is easy to create a fluent Support\Illuminate\Stringable object using the Str::of method.
For Example :
return (string) Str::of(' Laravel Framework 6.x ')
trim()
replace('6.x', '7.x')
slug();
return (string) Str::of(' Laravel Framework 6.x ') trim() replace('6.x', '7.x') slug();
New artisan commands
In Laravel 7 addition of a new artisan command : php artisan test
A New HTTP client
This is used for a request to API endpoints.
POST Request
<?php
use Illuminate\Support\Facades\Http;
$response = Http::post($url);
$response = Http::post($url, ['site' => 'Laravel 7',
]);
<?php use Illuminate\Support\Facades\Http; $response = Http::post($url); $response = Http::post($url, ['site' => 'Laravel 7', ]);
GET Request
$response = Http::get($url);
$response = Http::get($url,['abc'=>'xyz']);
$response = Http::get($url); $response = Http::get($url,['abc'=>'xyz']);
With Header
$response = Http::withHeaders(['abc' => 'xyz'])->
post($url, [
'baz' => 'qux',
]);
$response = Http::withHeaders(['abc' => 'xyz'])-> post($url, [ 'baz' => 'qux', ]);
Response
$response['abc']
$response->body()
$response->json()
$response->status()
$response->ok()
$response['abc'] $response->body() $response->json() $response->status() $response->ok()
Multiple Mail Drivers
Using Multiple Mail Drivers feature of Laravel 7, Now you can configure multiple mail drivers in a single application and it is configured within mail configuration file with its own options, Own unique “transport”, which allows application to use different email services to send certain email messages. I.e If you want to send single transaction mail then it will use Postmark and for bulk email it will use Amazon SES.
Laravel will use the mailer which is configured as a default mailer in configuration file but if you want to specify different mailer methods to send messages then you can specify it in mailer configuration.
Sending Mail Via A Specific Mailer
Mail::mailer('postmark')
->to($request->user())
->send(new OrderShipped($order));
Mail::mailer('postmark') ->to($request->user()) ->send(new OrderShipped($order));