• Welcome to Odoo Professional Consulting Agency
What Is New In Laravel 7 ? List Of All New Features

What Is New In Laravel 7 ? List Of All New Features

What Is New In Laravel 7 ?  List Of All New Features 


The latest version of Laravel 7 has been released on March 3rd, 2020 and As per support policy, This release is not LTS version and they will provide a 6-month bug fix until September 3rd, 2020, Security Fixes Until March 3rd, 2021.


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));

Cross-Origin Resource Sharing (CORS Support)


Laravel can automatically give response to CORS OPTIONS requests with values which you have configured. You can configure all your CORS settings in cors configuration file and its OPTIONS requests will naturally be taken care by the HandleCors middleware which is available by default in your global middleware stack.


Conclusion :

The latest version of Laravel 7 with some new features including routing speed, Blade component tags, New artisan commands and Multiple Mail driver etc. Please check the complete list from Release Notes as well as Upgrade Guide. You can contact our expert team for Laravel Development Services to build web applications using the latest version of Laravel. 

 

There are no comments for now.

Protected by reCAPTCHA, Privacy Policy & Terms of Service apply.
Which is Better PHP Framework? Laravel Or Codeigniter ?