版本資訊

版本策略

Laravel 及其第一方套件都遵守 語義化版本。框架的主要更新會每年釋出 (約在第一季),而次版本與修訂版則可能頻繁到每週更新。此版本與修訂版 絕對不會 包含中斷性變更 (Breaking Change)。

由於 Laravel 的主要更新會包含中斷性變更,因此在專案或套件中參照 Laravel 框架或其組件時,應使用如 ^10.0 這樣的版本限制式。不過,我們也會不斷努力確保每次進行主要版本更新時,都可於一天之內升級完成。

帶名稱的引數

帶名稱引數功能尚未包含在 Laravel 的向下相容性方針內。我們可能會在有必要的時候更改函式的參數名稱以改進 Laravel 的程式碼。因此,在使用帶名稱引數呼叫 Laravel 方法時應格外注意,並瞭解到引數名稱未來可能會有所更改。

支援政策

所有的 Laravel 版本都提供 18 個月的 Bug 修正,以及 2 年的安全性修正。對於其他的函式庫,如 Lumen,則只有最新的主要版本會收到 Bug 修正。此外,也請參考 Laravel 支援的資料庫版本。

版本PHP (*)釋出日期Bug 修正期限安全性修正期限
87.3 - 8.12020 年 9 月 8 日2022 年 7 月 26 日2023 年 1 月 24 日
98.0 - 8.22022 年 2 月 8 日2023 年 8 月 8 日2024 年 2 月 6 日
108.1 - 8.22023 年第 1 季2024 年 8 月 6 日2025 年 2 月 4 日
118.22024 年第 1 季2025 年 8 月 5 日2026 年 2 月 3 日
End of life
Security fixes only

(*) 支援的 PHP 版本

Laravel 10

讀者可能已經知道,從 Laravel 8 開始,Laravel 改為每年釋出新的主要版本。在此之前,每 6 個月都會釋出主要版本。這個改變是為了降低社群維護的負擔,並讓我們的開發團隊能想辦法在不包含中斷性更改 (Breaking Change) 的情況下繼續提供驚艷且強大的新功能。因此,我們在 Laravel 9 中,以不破壞向下相容性的前提下推出了許多強健的功能。

因此,我們對於在目前版本中釋出新功能的承諾也將導致未來的「主要 (Major)」版本將著重於一些「維護性」的任務,如更新上游套件等,讀者稍後可以在本版本資訊內讀到。

Laravel 10 在 Laravel 9.x 的基礎上繼續進行了諸多改進,包含在專案 Skeleton 中以及 Laravel 用來產生類別的 Stub 檔案中加上了回傳型別,並為所有引數加上型別。此外,我們還新增了一個對開發者友善的抽象層,可用來啟動與使用外部處理程序。而且,我們還推出了 Laravel Pennant,為你提供管理專案「Feature Flag(功能旗標)」的優質方案。

PHP 8.1

Laravel 10.x 所要求的最小 PHP 版本為 8.1。

型別

專案 Skeleton 與 Stub 的型別提示由 Nuno Maduro 參與貢獻

在 Laravel 最初的版本中,我們使用了當時 PHP 內能用的所有型別提示 (Type-hint) 功能。不過,在接下來的幾年中,PHP 不斷推出新功能,包含原生型別的型別提示、回傳型別、等位型別 (Union Type) 等。

在 Laravel 10.x 中,我們完全更新了專案的 Skeleton 與 Laravel 所使用的所有 Stub 檔案,以在這些檔案中為所有的方法簽章 (Method Signature) 上加上引數的型別提示與回傳型別。此外,還刪除了不必要的「Doc Block」型別提示:

1<?php
2 
3namespace App\Http\Controllers;
4 
5use App\Models\Flight;
6use Illuminate\Http\RedirectResponse;
7use Illuminate\Http\Request;
8use Illuminate\Http\Response;
9 
10class FlightController extends Controller
11{
12 /**
13 * Display a listing of the resource.
14 */
15 public function index(): Response
16 {
17 //
18 }
19 
20 /**
21 * Display the specified resource.
22 */
23 public function show(Flight $flight): Response
24 {
25 //
26 }
27 
28 // ...
29 
30}
1<?php
2 
3namespace App\Http\Controllers;
4 
5use App\Models\Flight;
6use Illuminate\Http\RedirectResponse;
7use Illuminate\Http\Request;
8use Illuminate\Http\Response;
9 
10class FlightController extends Controller
11{
12 /**
13 * Display a listing of the resource.
14 */
15 public function index(): Response
16 {
17 //
18 }
19 
20 /**
21 * Display the specified resource.
22 */
23 public function show(Flight $flight): Response
24 {
25 //
26 }
27 
28 // ...
29 
30}

對於現有專案來說,這項更改是完全向下相容的。因此,現有專案若沒有型別提示,也能繼續正常運作:

Laravel Pennant

Laravel Pennant 由 Tim MacDonald 開發

第一方套件,Laravel Pennant,現已推出。Laravel Pennant 提供了輕量、簡化的方法,能讓你管理專案的 Feature Flag。在 Pennant 中包含了現成的 array Driver 與 database Driver 可用來保存 Feature。

使用 Feature::define 方法就能輕鬆定義 Feature:

1use Laravel\Pennant\Feature;
2use Illuminate\Support\Lottery;
3 
4Feature::define('new-onboarding-flow', function () {
5 return Lottery::odds(1, 10);
6});
1use Laravel\Pennant\Feature;
2use Illuminate\Support\Lottery;
3 
4Feature::define('new-onboarding-flow', function () {
5 return Lottery::odds(1, 10);
6});

定義好 Feature 後,可以輕鬆判斷目前使用者是否能存取該功能:

1if (Feature::active('new-onboarding-flow')) {
2 // ...
3}
1if (Feature::active('new-onboarding-flow')) {
2 // ...
3}

當然,為了讓開發起來更方便,我們也提供了 Blade 指示詞:

1@feature('new-onboarding-flow')
2 <div>
3 <!-- ... -->
4 </div>
5@endfeature
1@feature('new-onboarding-flow')
2 <div>
3 <!-- ... -->
4 </div>
5@endfeature

Pennant 還提供了更多進階的功能與 API。更多資訊請參考完整的 Pennant 說明文件

使用 Process

Process 的抽象層由 Nuno MaduroTaylor Otwell 參與貢獻

Laravel 10.x 中推出了一個新的 Process Facade,這個出色的抽象層可用來啟動與操縱外部處理程序 (Process):

1use Illuminate\Support\Facades\Process;
2 
3$result = Process::run('ls -la');
4 
5return $result->output();
1use Illuminate\Support\Facades\Process;
2 
3$result = Process::run('ls -la');
4 
5return $result->output();

也可以使用集區 (Pool) 的方式啟動處理程序,以更方便的執行與管理平行執行的處理程序:

1use Illuminate\Process\Pool;
2use Illuminate\Support\Facades\Pool;
3 
4[$first, $second, $third] = Process::concurrently(function (Pool $pool) {
5 $pool->command('cat first.txt');
6 $pool->command('cat second.txt');
7 $pool->command('cat third.txt');
8});
9 
10return $first->output();
1use Illuminate\Process\Pool;
2use Illuminate\Support\Facades\Pool;
3 
4[$first, $second, $third] = Process::concurrently(function (Pool $pool) {
5 $pool->command('cat first.txt');
6 $pool->command('cat second.txt');
7 $pool->command('cat third.txt');
8});
9 
10return $first->output();

此外,也可以模擬 Process 以方便測試:

1Process::fake();
2 
3// ...
4 
5Process::assertRan('ls -la');
1Process::fake();
2 
3// ...
4 
5Process::assertRan('ls -la');

更多有關使用 Process 的資訊,請參考完整的 Process 說明文件

測試分析

測試分析由 Nuno Maduro 參與貢獻

Artisan 的 test 指令有了一個全新的 --profile 選項,能讓你輕鬆的找到專案中最慢的測試:

1php artisan test --profile
1php artisan test --profile

為了方便起見,最慢的測試會直接在 CLI 的輸出中顯示出來:

Pest 的 Scaffold

現在,新建立的 Laravel 專案中可以使用 Pest 測試來 Scaffold。若要使用這個功能,請在使用 Laravel 安裝程式建立新專案時提供 --pest 旗標:

1laravel new example-application --pest
1laravel new example-application --pest

產生 CLI 提示字元

產生 CLI 提示字元由 Jess Archer 參與貢獻

為了改進 Laravel 所提供的開發者經驗,Laravel 內所有內建的 make 指令現在已不再需要任何輸入。在執行這些指令時,若未提供輸入,則會被提示輸入必要的引數:

1php artisan make:controller
1php artisan make:controller
翻譯進度
100% 已翻譯
更新時間:
2023年2月11日 下午12:59:00 [世界標準時間]
翻譯人員:
  • cornch
幫我們翻譯此頁

留言

尚無留言

“Laravel” is a Trademark of Taylor Otwell.
The source documentation is released under MIT license. See laravel/docs on GitHub for details.
The translated documentations are released under MIT license. See cornch/laravel-docs-l10n on GitHub for details.