In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what new features Laravel 8 has, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
Laravel 8 was officially released yesterday (non-LTS version). This major release introduces new features such as Laravel Jetstream, model class directory, model factory class, migration file compression, frequency limit optimization, time test helper function, dynamic Blade component, etc.
Note: Some students feedback why Laravel versions are released so frequently, that is because a new version release cycle has been introduced since Laravel 6. For details, please refer to this tutorial published by Academy Jun before: Introduction to the release cycle of new versions after Laravel 6.
Here's a quick look at these new features:
Laravel Jetstream
Laravel Jetstream is an optimized and completely redesigned Laravel UI scaffolding code over previous versions:
It includes login, registration, mailbox authentication, two-factor authentication (2FA), session management, API support based on Laravel Sanctum, and optional team management.
Jetstream uses Tailwind CSS as its CSS framework and offers Livewire and Inertia scaffolding options, which you can choose for front-end component development.
Model class catalog
Laravel 8 finally introduced the Models subdirectory in the app directory to store model class files. All model classes generated by the make:model command will be stored in this directory by default; however, if you choose to delete this directory, newly generated model classes will still be stored in the app directory.
Model Factory Class
Starting with Laravel 8, Eloquent model factories will be managed on a class-based basis to support associations between different factories. The new model factory call syntax is shown below, which is more readable than before:
use App\Models\User;
User::factory()->count(50)->create();
//Use the "suspended" association method defined in the factory class
User::factory()->count(5)->suspended()->create();
Migration file compression
As applications become more complex, you need to create more and more database migration files, possibly hundreds, which can be a bit cumbersome to manage, starting with Laravel 8, you can compress them into a single SQL file, which is executed before running the migration command, and then execute other uncompressed migration files. This feature effectively reduces the number of migrated files and improves performance during testing.
Optimize access frequency
Laravel 8 optimizes the frequency restriction feature that already existed--supports backward compatibility with throttle middleware, and provides greater flexibility. Laravel 8 introduces an access frequency limiter that can be defined by the facade:
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('global', function (Request $request) {
return Limit::perMinute(1000);
});
As you can see, the for method holds HTTP request samples, so you can completely control the frequency of requests dynamically.
time test auxiliary function
In Laravel, time modification has always been completely controlled through the PHP Carbon library, but Laravel 8 takes this one step further-using a more convenient helper function to manipulate time during testing:
//Go to the future...
$this->travel(5)->milliseconds();
$this->travel(5)->seconds();
$this->travel(5)->minutes();
$this->travel(5)->hours();
$this->travel(5)->days();
$this->travel(5)->weeks();
$this->travel(5)->years();
//Go back to the past...
$this->travel(-5)->hours();
The requested URL//was not found.
$this->travelTo(now()->subHours(6));
//Back to the present...
$this->travelBack();
When using these methods, time resets between each test.
Dynamic Blade Assembly
Sometimes you may need to render Blade components dynamically at runtime, Laravel 8 provides a component to do this:
Thank you for reading this article carefully. I hope that the article "What are the new features of Laravel 8" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.