search
HomeheadlinesLaravel 7 is about to be released, let's take a look at what new features and functions it has!

Laravel 7 is about to be released, let's take a look at what new features and functions it has!

The official release date of Laravel 7 is March 3, 2020. According to Laravel Framework's major laravel version release policy every 6 months (February and August), it is another major version. It is not an LTS release, so according to the Laravel release support policy, they provide 6 months of bug fix support until September 3, 2020, and 1 year of security issue fix support until March 3, 2021. Let’s take a look at the new features and improvements in Laravel 7. (laravel technical article)

New features of Laravel 7

● Laravel Airlock

● Zttp for HTTP client

● CORS support

● Custom Eloquent Cast

● Smooth string operation

● Blade X

● Customizable Stubs

● Query Time Conversion

● Multiple Mail Drivers

● New Artisan Commands

Improvements in Laravel 7

● Routing model binding improvements

● 2x faster routing

● Database queue improvements

● Markdown email template improvements

● And more bug fixes and improvements.

Laravel Airlock

Laravel Airlock is the official package for API authentication. It provides simple token-based API authentication, token issuance, token capabilities, mobile app authentication, and more.

Zttp for HTTP Client

Using Zttp, making HTTP requests to the API would be a better and more concise approach.

Post request

<?php
use Illuminate\Support\Facades\Http;
$response = Http::post($url);
$response = Http::post($url, [
    &#39;site&#39; => &#39;Laravel Article&#39;,
]);

Get response

$response = Http::get($url);
$response = Http::get($url,[&#39;foo&#39;=>&#39;bar&#39;]);

With request header

$response = Http::withHeaders([&#39;foo&#39; => &#39;bar&#39;])->post($url, [
    &#39;baz&#39; => &#39;qux&#39;,
]);

Response

$response[&#39;foo&#39;]
$response->body()
$response->json()
$response->status()
$response->ok()

CORS support

Laravel 7 now supports CORS (Cross-Origin Resource Sharing) out of the box. You should better understand that every developer has encountered CORS issues in API development. Laravel 7 now automatically responds to OPTION requests using configuration values. Laravel 7 comes with HandleCors middleware out of the box that does it all.

Custom Eloquent Cast

Custom eloquent casting in Laravel 7 is another cool feature. This feature will enable you to add custom casts. Let's take a look at JSON Caster.

<?php
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class Json implements CastsAttributes
{
    public function get($model, $key, $value, $attributes)
    {
        return json_decode($value, true);
    }
    public function set($model, $key, $value, $attributes)
    {
        return json_encode($value);
    }
}

Now, we can use the custom eloquent cast in the model.

<?php
namespace App;
use App\Casts\Json;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
    protected $casts = [
        &#39;extra&#39; => Json::class,
    ];
}

Fluent String Operations

In Laravel 7, you can use the Illuminate\Support\Str class to do more cool object-oriented things.

$currentVersion = (string) Str::of(&#39;  Laravel 6.x &#39;);
return $currentVersion->trim()
        ->replace(&#39;6.x&#39;, &#39;7.x&#39;)
        ->slug();
// laravel-7x

Blade X

Laravel 7 Blade X features enable you to make class-less components.

Generate x-component

@php($user = $user ?? Auth::user())
@php($size = $size ?? 50)
<img  class="inline-block rounded-full lazy"  src="/static/imghwm/default1.png"  data-src="{{ $user- alt="Laravel 7 is about to be released, let's take a look at what new features and functions it has!" >gravatarUrl($size) }}" 
    
    
    width="{{ $size }}"
    height="{{ $size }}"
/>

Blade x Usage

<x-avatar/>
<x-avatar size="40" />
<x-avatar size="100" />

Customize Stubs

Now you can use artisan command in Custom stubs in Laravel 7.x.

php artisan stub:publish

Query Time Conversion

Laravel 7 provides the withCasts method to help you cast values ​​while running a query. Let's give an example.

$users = User::select([
    &#39;users.*&#39;,
    &#39;last_posted_at&#39; => Post::selectRaw(&#39;MAX(created_at)&#39;)->whereColumn(&#39;user_id&#39;, &#39;users.id&#39;)
])
->withCasts([&#39;last_posted_at&#39; => &#39;date&#39;])
->get();

Multiple Mail Drivers

Laravel 7 will allow you to set up multiple mail drivers using a single application.

Mail::mailer(&#39;noreply&#39;)
        ->to($request->user())
        ->send(new PostUpdated($post));

New Artisan Command

A new artisan test command has been added to Laravel 7. The new artisan test command gives you a beautiful UX and useful information about your tests.

php artisan test

Improvements in Laravel 7

● Routing model binding improvements

● 2x faster routing

● Database queue improvements

● Markdown email template improvements

● and more bug fixes and improvements.

Route model binding improvements

Custom Key

By default, route model binding is used with the id field. Now you can customize it.

Route::get(&#39;posts/{post:slug}&#39;, function (App\Post $post) {
    return $post;
});

Auto-scoping

Laravel 7 will automatically scope queries to retrieve nested models using the method it identifies conventions for identifying relation calls in your program.

use App\Post;
use App\User;
Route::get(&#39;api/users/{user}/posts/{post:slug}&#39;, function (User $user, Post $post) {
    return $post;
});

2x faster routing

When using route:cache, Laravel 7’s route matching performance is 2x faster than laravel 6

Database Queue Improvements

Laravel 7 has improvements for applications that use MySQL 8 as a database-backed queue.

Markdown email template improvements

The default markdown template for emails has a newer look using the Tailwind CSS palette. Templates can be published and customized as needed.

For more programming related content, please pay attention to the Programming Introduction column on the php Chinese website!

Statement
This article is reproduced at:NiZerin. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.