یادداشت های انتشار
طرح نسخه سازی
لاراول و سایر بستههای شخص اول آن از Semantic Versioning پیروی میکنند . نسخههای اصلی فریمورک هر سال (~ فوریه) منتشر میشوند، در حالی که نسخههای جزئی و وصله ممکن است هر هفته منتشر شوند. نسخه های جزئی و پچ هرگز نباید حاوی تغییرات شکسته باشند.
هنگام ارجاع به چارچوب لاراول یا اجزای آن از برنامه یا بسته خود، همیشه
باید از یک محدودیت نسخه مانند استفاده کنید
^9.0
، زیرا نسخه های اصلی لاراول شامل تغییرات شکسته می شوند. با این حال، ما
تلاش میکنیم همیشه اطمینان حاصل کنیم که میتوانید یک نسخه اصلی جدید را در یک روز یا کمتر بهروزرسانی کنید.
آرگومان های نامگذاری شده
آرگومان های نامگذاری شده توسط دستورالعمل های سازگاری با عقب لاراول پوشش داده نمی شوند. ممکن است در صورت لزوم تغییر نام آرگومان های تابع را برای بهبود پایگاه کد لاراول انتخاب کنیم. بنابراین، استفاده از آرگومان های نامگذاری شده هنگام فراخوانی متدهای لاراول باید با احتیاط و با درک این موضوع انجام شود که نام پارامترها ممکن است در آینده تغییر کند.
خط مشی پشتیبانی
برای تمامی نسخههای لاراول، رفع اشکال به مدت 18 ماه و رفعهای امنیتی به مدت 2 سال ارائه میشود. برای همه کتابخانههای اضافی، از جمله Lumen، فقط آخرین نسخه اصلی رفع اشکال را دریافت میکند. علاوه بر این، لطفاً نسخه های پایگاه داده پشتیبانی شده توسط لاراول را بررسی کنید .
نسخه | PHP (*) | رهایی | رفع اشکال تا زمانی که | رفع امنیتی تا |
---|---|---|---|---|
6 (LTS) | 7.2 - 8.0 | 3 سپتامبر 2019 | 25 ژانویه 2022 | 6 سپتامبر 2022 |
7 | 7.2 - 8.0 | 3 مارس 2020 | 6 اکتبر 2020 | 3 مارس 2021 |
8 | 7.3 - 8.1 | 8 سپتامبر 2020 | 26 جولای 2022 | 24 ژانویه 2023 |
9 | 8.0 - 8.2 | 8 فوریه 2022 | 8 آگوست 2023 | 6 فوریه 2024 |
10 | 8.1 - 8.2 | Q1 2023 | 6 آگوست 2024 | 4 فوریه 2025 |
(*) نسخه های PHP پشتیبانی شده
لاراول 9
همانطور که می دانید، لاراول با انتشار لاراول 8 به نسخه های سالانه تبدیل شد. پیش از این، نسخه های اصلی هر 6 ماه یکبار منتشر می شد. این انتقال به منظور کاهش بار تعمیر و نگهداری بر روی جامعه و به چالش کشیدن تیم توسعه ما برای ارسال ویژگیهای جدید شگفتانگیز و قدرتمند بدون ایجاد تغییرات اساسی است. بنابراین، ما انواع مختلفی از ویژگیهای قوی را به لاراول 8 ارسال کردهایم که سازگاری با عقب را شکسته است، مانند پشتیبانی از آزمایش موازی، کیتهای استارت بهبود یافته Breeze، بهبودهای کلاینت HTTP، و حتی انواع روابط جدید Eloquent مانند "یکی از چندین" را دارد.
بنابراین، این تعهد به ارسال ویژگیهای جدید عالی در طول نسخه فعلی احتمالاً منجر به این خواهد شد که نسخههای «مهم» آینده عمدتاً برای کارهای «نگهداری» مانند ارتقاء وابستگیهای بالادستی مورد استفاده قرار گیرند، که در این یادداشتهای انتشار قابل مشاهده است.
لاراول 9 با ارائه پشتیبانی از اجزای Symfony 6.0، Symfony Mailer،
Flysystem 3.0،
route:list
خروجی بهبودیافته، درایور پایگاه داده Laravel Scout، نحو جدید Eloquent
accessor/mutator، اتصالات مسیر ضمنی از طریق Enum، به بهبودهای ایجاد شده در Laravel 8.x ادامه میدهد.
رفع اشکال دیگر و بهبود قابلیت استفاده.
PHP 8.0
لاراول 9.x به حداقل نسخه PHP 8.0 نیاز دارد.
سیمفونی میلر
حمایت Symfony Mailer توسط Dries Vints , James Brooks و Julius Kiekbusch انجام شد .
نسخههای قبلی لاراول از کتابخانه Swift Mailer برای ارسال ایمیلهای خروجی استفاده میکرد. با این حال، آن کتابخانه دیگر نگهداری نمی شود و Symfony Mailer جانشین آن شده است.
لطفاً راهنمای ارتقا را مرور کنید تا در مورد اطمینان از سازگاری برنامه خود با Symfony Mailer بیشتر بدانید.
Flysystem 3.x
پشتیبانی Flysystem 3.x توسط Dries Vints ارائه شده است .
لاراول 9.x وابستگی بالادستی Flysystem ما را به Flysystem 3.x ارتقا
میدهد. Flysystem تمام فعل و انفعالات سیستم فایل ارائه شده توسط
Storage
نما را تامین می کند.
لطفاً راهنمای ارتقا را مرور کنید تا در مورد اطمینان از سازگاری برنامه خود با Flysystem 3.x اطلاعات بیشتری کسب کنید.
بهبود یافته های الکوئنت / جهش دهنده ها
بهبود یافته های Eloquent / mutators توسط Taylor Otwell ارائه شد .
Laravel 9.x راه جدیدی برای تعریف دسترسیها و جهشدهندههای Eloquent ارائه میکند . در نسخههای قبلی لاراول، تنها راه برای تعریف دسترسیها و جهشدهندهها این بود که متدهای پیشوندی را در مدل خود تعریف کنید:
public function getNameAttribute($value){ return strtoupper($value);} public function setNameAttribute($value){ $this->attributes['name'] = $value;}
با این حال، در لاراول 9.x میتوانید با استفاده از یک روش بدون پیشوند، یک
Accessor و mutator را با تایپ کردن نوع بازگشتی تعریف کنید
Illuminate\Database\Eloquent\Casts\Attribute
:
use Illuminate\Database\Eloquent\Casts\Attribute; public function name(): Attribute{ return new Attribute( get: fn ($value) => strtoupper($value), set: fn ($value) => $value, );}
علاوه بر این، این رویکرد جدید برای تعریف دسترسیها، مقادیر شی را که توسط صفت برگردانده میشوند را در حافظه پنهان میکند، درست مانند کلاسهای Cast سفارشی :
use App\Support\Address;use Illuminate\Database\Eloquent\Casts\Attribute; public function address(): Attribute{ return new Attribute( get: fn ($value, $attributes) => new Address( $attributes['address_line_one'], $attributes['address_line_two'], ), set: fn (Address $value) => [ 'address_line_one' => $value->lineOne, 'address_line_two' => $value->lineTwo, ], );}
Enum Eloquent Attribute Casting
فرستادن Enum فقط برای PHP 8.1 و بالاتر در دسترس است.
بازیگری Enum توسط محمد سعید انجام شد .
Eloquent اکنون به شما این امکان را می دهد که مقادیر ویژگی خود را به
Enums "پشتیبانی شده"
PHP ارسال کنید . برای انجام این کار، میتوانید ویژگی و شمارهای را که
میخواهید در
$casts
آرایه ویژگی مدل خود قرار دهید را مشخص کنید:
use App\Enums\ServerStatus; /** * The attributes that should be cast. * * @var array */protected $casts = [ 'status' => ServerStatus::class,];
هنگامی که cast را روی مدل خود تعریف کردید، هنگامی که با ویژگی تعامل می کنید، ویژگی مشخص شده به طور خودکار به و از یک enum فرستاده می شود:
if ($server->status == ServerStatus::Provisioned) { $server->status = ServerStatus::Ready; $server->save();}
اتصالات مسیر ضمنی با Enums
پیوندهای ضمنی Enum توسط Nuno Maduro ارائه شده است .
PHP 8.1 پشتیبانی از Enums را معرفی می کند . لاراول 9.x توانایی تایپ Enum را در تعریف مسیر شما معرفی میکند و لاراول تنها در صورتی مسیر را فراخوانی میکند که آن بخش مسیر یک مقدار Enum معتبر در URI باشد. در غیر این صورت، پاسخ HTTP 404 به طور خودکار برگردانده می شود. به عنوان مثال، با توجه به Enum زیر:
enum Category: string{ case Fruits = 'fruits'; case People = 'people';}
می توانید مسیری را تعریف کنید که فقط در صورتی فراخوانی شود که
{category}
بخش مسیر
fruits
یا
people
. در غیر این صورت، یک پاسخ HTTP 404 برگردانده خواهد شد:
Route::get('/categories/{category}', function (Category $category) { return $category->value;});
محدوده اجباری اتصالات مسیر
اتصالات با محدوده اجباری توسط کلودیو دکر ارائه شد .
در نسخههای قبلی لاراول، ممکن است بخواهید مدل دوم Eloquent را در یک تعریف مسیر قرار دهید به طوری که باید فرزند مدل Eloquent قبلی باشد. به عنوان مثال، این تعریف مسیر را در نظر بگیرید که یک پست وبلاگ را توسط اسلاگ برای یک کاربر خاص بازیابی می کند:
use App\Models\Post;use App\Models\User; Route::get('/users/{user}/posts/{post:slug}', function (User $user, Post $post) { return $post;});
هنگام استفاده از یک اتصال ضمنی با کلید سفارشی به عنوان پارامتر مسیر تودرتو، لاراول به طور خودکار محدوده پرس و جو را برای بازیابی مدل تودرتو توسط والد خود با استفاده از قراردادها برای حدس زدن نام رابطه روی والد، بررسی می کند. با این حال، این رفتار قبلاً توسط لاراول پشتیبانی میشد که یک کلید سفارشی برای اتصال مسیر فرزند استفاده میشد.
با این حال، در لاراول 9.x، اکنون میتوانید به لاراول دستور دهید تا محدوده
اتصالات «کودک» را حتی زمانی که یک کلید سفارشی ارائه نشده است، محدود کند. برای انجام این کار، می توانید
scopeBindings
در هنگام تعریف مسیر خود از روش استفاده کنید:
use App\Models\Post;use App\Models\User; Route::get('/users/{user}/posts/{post}', function (User $user, Post $post) { return $post;})->scopeBindings();
یا، ممکن است به یک گروه کامل از تعاریف مسیر دستور دهید تا از اتصالات محدوده استفاده کنند:
Route::scopeBindings()->group(function () { Route::get('/users/{user}/posts/{post}', function (User $user, Post $post) { return $post; });});
گروه های مسیر کنترلر
Route group improvements were contributed by Luke Downing.
You may now use the controller
method to define the common controller for all of the routes within the
group. Then, when defining the routes, you only need to provide the controller method that they invoke:
use App\Http\Controllers\OrderController; Route::controller(OrderController::class)->group(function () { Route::get('/orders/{id}', 'show'); Route::post('/orders', 'store');});
Full Text Indexes / Where Clauses
Full text indexes and "where" clauses were contributed by Taylor Otwell and Dries Vints.
When using MySQL or PostgreSQL, the fullText
method may now be added to column definitions to generate
full text indexes:
$table->text('bio')->fullText();
In addition, the whereFullText
and orWhereFullText
methods may be used to add full text
"where" clauses to a query for columns that have full text
indexes. These methods will be transformed into the appropriate SQL for the underlying database system by
Laravel. For example, a MATCH AGAINST
clause will be generated for applications utilizing MySQL:
$users = DB::table('users') ->whereFullText('bio', 'web developer') ->get();
Laravel Scout Database Engine
The Laravel Scout database engine was contributed by Taylor Otwell and Dries Vints.
If your application interacts with small to medium sized databases or has a light workload, you may now use Scout's "database" engine instead of a dedicated search service such as Algolia or MeiliSearch. The database engine will use "where like" clauses and full text indexes when filtering results from your existing database to determine the applicable search results for your query.
To learn more about the Scout database engine, consult the Scout documentation.
Rendering Inline Blade Templates
Rendering inline Blade templates was contributed by Jason Beggs. Rendering inline Blade components was contributed by Toby Zerner.
Sometimes you may need to transform a raw Blade template string into valid HTML. You may accomplish this using the
render
method provided by the Blade
facade. The render
method accepts the
Blade template string and an optional array of data to provide to the template:
use Illuminate\Support\Facades\Blade; return Blade::render('Hello, {{ $name }}', ['name' => 'Julian Bashir']);
Similarly, the renderComponent
method may be used to render a given class component by passing the
component instance to the method:
use App\View\Components\HelloComponent; return Blade::renderComponent(new HelloComponent('Julian Bashir'));
Slot Name Shortcut
Slot name shortcuts were contributed by Caleb Porzio.
In previous releases of Laravel, slot names were provided using a name
attribute on the
x-slot
tag:
<x-alert> <x-slot name="title"> Server Error </x-slot> <strong>Whoops!</strong> Something went wrong!</x-alert>
However, beginning in Laravel 9.x, you may specify the slot's name using a convenient, shorter syntax:
<x-slot:title> Server Error</x-slot>
Checked / Selected Blade Directives
Checked and selected Blade directives were contributed by Ash Allen and Taylor Otwell.
For convenience, you may now use the @checked
directive to easily indicate if a given HTML checkbox
input is "checked". This directive will echo checked
if the provided condition evaluates to
true
:
<input type="checkbox" name="active" value="active" @checked(old('active', $user->active)) />
Likewise, the @selected
directive may be used to indicate if a given select option should be "selected":
<select name="version"> @foreach ($product->versions as $version) <option value="{{ $version }}" @selected(old('version') == $version)> {{ $version }} </option> @endforeach</select>
Bootstrap 5 Pagination Views
Bootstrap 5 pagination views were contributed by Jared Lewis.
Laravel now includes pagination views built using Bootstrap 5. To use these
views instead of the default Tailwind views, you may call the paginator's useBootstrapFive
method
within the boot
method of your App\Providers\AppServiceProvider
class:
use Illuminate\Pagination\Paginator; /** * Bootstrap any application services. * * @return void */public function boot(){ Paginator::useBootstrapFive();}
Improved Validation Of Nested Array Data
Improved validation of nested array inputs was contributed by Steve Bauman.
Sometimes you may need to access the value for a given nested array element when assigning validation rules to the
attribute. You may now accomplish this using the Rule::forEach
method. The forEach
method
accepts a closure that will be invoked for each iteration of the array attribute under validation and will receive
the attribute's value and explicit, fully-expanded attribute name. The closure should return an array of rules to
assign to the array element:
use App\Rules\HasPermission;use Illuminate\Support\Facades\Validator;use Illuminate\Validation\Rule; $validator = Validator::make($request->all(), [ 'companies.*.id' => Rule::forEach(function ($value, $attribute) { return [ Rule::exists(Company::class, 'id'), new HasPermission('manage-company', $value), ]; }),]);
Laravel Breeze API & Next.js
The Laravel Breeze API scaffolding and Next.js starter kit was contributed by Taylor Otwell and Miguel Piedrafita.
The Laravel Breeze starter kit has received an "API" scaffolding mode and complimentary Next.js frontend implementation. This starter kit scaffolding may be used to jump start your Laravel applications that are serving as a backend, Laravel Sanctum authenticated API for a JavaScript frontend.
Improved Ignition Exception Page
Ignition is developed by Spatie.
Ignition, the open source exception debug page created by Spatie, has been redesigned from the ground up. The new, improved Ignition ships with Laravel 9.x and includes light / dark themes, customizable "open in editor" functionality, and more.
Improved route:list
CLI Output
Improved route:list
CLI output was contributed by Nuno
Maduro.
The route:list
CLI output has been significantly improved for the Laravel 9.x release, offering a
beautiful new experience when exploring your route definitions.
Test
Coverage Using Artisan test
Command
Test coverage when using the Artisan test
command was contributed by Nuno Maduro.
The Artisan test
command has received a new --coverage
option that you may use to explore
the amount of code coverage your tests are providing to your application:
php artisan test --coverage
The test coverage results will be displayed directly within the CLI output.
In addition, if you would like to specify a minimum threshold that your test coverage percentage must meet, you may
use the --min
option. The test suite will fail if the given minimum threshold is not met:
php artisan test --coverage --min=80.3
Soketi Echo Server
The Soketi Echo server was developed by Alex Renoki.
Although not exclusive to Laravel 9.x, Laravel has recently assisted with the documentation of Soketi, a Laravel Echo compatible Web Socket server written for Node.js. Soketi provides a great, open source alternative to Pusher and Ably for those applications that prefer to manage their own Web Socket server.
For more information on using Soketi, please consult the broadcasting documentation and Soketi documentation.
Improved Collections IDE Support
Improved collections IDE support was contributed by Nuno Maduro.
Laravel 9.x adds improved, "generic" style type definitions to the collections component, improving IDE and static analysis support. IDEs such as PHPStorm or static analysis tools such as PHPStan will now better understand Laravel collections natively.
New Helpers
Laravel 9.x introduces two new, convenient helper functions that you may use in your own application.
str
The str
function returns a new Illuminate\Support\Stringable
instance for the given string.
This function is equivalent to the Str::of
method:
$string = str('Taylor')->append(' Otwell'); // 'Taylor Otwell'
If no argument is provided to the str
function, the function returns an instance of
Illuminate\Support\Str
:
$snake = str()->snake('LaravelFramework'); // 'laravel_framework'
to_route
The to_route
function generates a redirect HTTP response for a given named route, providing an
expressive way to redirect to named routes from your routes and controllers:
return to_route('users.show', ['user' => 1]);
If necessary, you may pass the HTTP status code that should be assigned to the redirect and any additional response headers as the third and fourth arguments to the to_route method:
return to_route('users.show', ['user' => 1], 302, ['X-Framework' => 'Laravel']);