> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# 2026 年 10 月 Laravel 更新

> 2026 年 10 月 Laravel 13 與官方產品的更新。彙整 QUERY 路由、副本讀取過期的對策、排程的單一伺服器執行、Fake 的驗證、Cloud 的 Resend 整合，以及 Forge 的 PHP 更新通知。

2026 年 10 月新增了一些功能，用來控制請求的表達方式、資料庫的讀取目標，以及在多台伺服器上執行排程。Laravel Cloud 簡化了郵件寄送與定期執行的設定，Forge 則讓 PHP 安全更新與佈建失敗更容易掌握。

本頁是根據 11 月 4 日發布的官方部落格「Laravel October Product Updates」以及官方 Framework Changelog 10 月部分整理的月度紀錄。一手資料於 2026 年 11 月 7 日確認，Framework 部分僅涵蓋 Laravel 13 系列。不包含 11 月的發布。

參考來源：

* [Laravel October Product Updates](https://laravel.com/blog/laravel-october-product-updates)
* [Laravel Framework changelog — October 2026](https://laravel.com/framework/docs/changelog#log-2026-10)
* [Laravel Framework changelog RSS](https://laravel.com/rss/oss-changelog)

## Laravel Framework

### 10 月的發布範圍

除了官方 Changelog 中的主要新功能外，也根據發布說明確認了日期與導入版本。

| 發布 | 發布日期 | 主要變更 |
| - | - | - |
| [v13.35.0](https://github.com/laravel/framework/releases/tag/v13.35.0) | 10 月 6 日 | Fake 的屬性驗證、以比例指定 worker 記憶體、Markdown 回應、`alwaysOnOneServer()`、QUERY 路由。 |
| [v13.36.0](https://github.com/laravel/framework/releases/tag/v13.36.0) | 10 月 13 日 | Vitess 的 OLAP 執行、為既有驗證規則新增 Builder。 |
| [v13.37.0](https://github.com/laravel/framework/releases/tag/v13.37.0) | 10 月 16 日 | `Rule::numeric()` 的 strict 選項、修正同時使用 `onOneServer()` 與 `withoutOverlapping()` 時的競爭。 |
| [v13.38.0](https://github.com/laravel/framework/releases/tag/v13.38.0) | 10 月 20 日 | `PreventStaleDatabaseReads`、`Connection::usingWritePdo()`。 |
| [v13.39.0](https://github.com/laravel/framework/releases/tag/v13.39.0) | 10 月 27 日 | `RefreshDatabase` 在測試後回滾所有交易層級、修正 `assertSeeText('0')` 錯誤通過的問題。 |

以下詳細介紹官方 Changelog 中列出的 9 個項目。細微的修正與相依套件變更，請參閱各發布說明。

### 使用 QUERY 路由定義帶有請求本文的搜尋

v13.35.0 新增了對應 HTTP `QUERY` 方法的 `Route::query()`。可以定義透過請求本文而非 GET 查詢字串接收搜尋條件的路由。

```php theme={null}
use App\Http\Controllers\SearchProductsController;
use Illuminate\Support\Facades\Route;

Route::query('/products/search', SearchProductsController::class);
```

`Route::any()` 也會比對 QUERY 請求，路由清單也能辨識此方法。上方的 `SearchProductsController` 假設為應用程式中實作了搜尋處理的 Invokable Controller。

> [!WARNING]
>
> `web` 中介層群組中的 QUERY 路由會進行 CSRF 驗證。不要認為「既然是搜尋，就能像 GET 一樣省略驗證」，請傳送 CSRF 權杖。

一手資料：[Register QUERY Routes](https://laravel.com/framework/docs/changelog#october-2026-register-query-routes)、[Laravel 13 官方 routing.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/routing.md#available-router-methods)。相關頁面：[路由](https://kawax.biz/zh-TW/routing.md)、[CSRF 保護](https://kawax.biz/zh-TW/csrf.md)

### 在寫入後的其他請求中也避免讀取過期資料

在讀寫分離的資料庫中，更新後立即進行的讀取可能會送往尚未同步的 Read replica。既有的 `sticky` 設定只針對同一請求內，而 v13.38.0 的 `PreventStaleDatabaseReads` 會為同一工作階段的後續請求也設定保護期間。

在 `bootstrap/app.php` 中 import `Illuminate\Foundation\Http\Middleware\PreventStaleDatabaseReads`，並在 `withMiddleware()` 的回呼中以 `$middleware->web(append: [PreventStaleDatabaseReads::class]);` 加入。此功能不會自動啟用。

中介層會將對預設資料庫連線的寫入時間記錄到工作階段，預設在寫入後的 2 秒內將該連線的讀取送往 Write DB。可以將註冊的類別換成 `PreventStaleDatabaseReads::for(5)` 等來變更保護期間。

```mermaid theme={null}
sequenceDiagram
    participant User as 使用者
    participant App as Laravel<br>應用程式
    participant Session as 工作階段
    participant Write as Write DB
    participant Read as Read replica
    User->>App: 更新請求
    App->>Write: 寫入資料
    App->>Session: 記錄寫入時間
    User->>App: 同一工作階段的下一個請求
    App->>Session: 確認寫入後經過的時間
    alt 在 2 秒保護期間內
        App->>Write: 讀取資料
    else 保護期間之後
        App->>Read: 使用一般讀取目標
    end
```

由於使用工作階段，必須在 `StartSession` 之後執行。它不會切換其他工作階段或其他資料庫連線的讀取，也不會偵測副本是否已完成同步。

一手資料：[Avoid Stale Reads After Database Writes](https://laravel.com/framework/docs/changelog#october-2026-avoid-stale-reads-after-database-writes)、[Laravel 13 官方 database.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/database.md#preventing-stale-database-reads)。相關頁面：[資料庫](https://kawax.biz/zh-TW/database.md)、[Session](https://kawax.biz/zh-TW/session.md)

### 只讓特定處理從 Write DB 讀取

同樣在 v13.38.0 新增的 `Connection::usingWritePdo()`，只在回呼執行期間將該連線的讀取目標切換到 Write DB。它不是以工作階段為單位的保護，適合想在應用程式中明確指定重要讀取範圍的情況。

```php theme={null}
use Illuminate\Support\Facades\DB;

$users = DB::connection()->usingWritePdo(
    fn ($connection) => $connection->table('users')->get()
);
```

它也適用於使用同一連線的 Eloquent 查詢與關聯查詢。它會回傳回呼的結果，即使發生例外也會還原先前的讀取設定，因此切換不會殘留到後續處理。

一手資料：[Temporarily Read from the Write Database Connection](https://laravel.com/framework/docs/changelog#october-2026-temporarily-read-from-the-write-database-connection)、[Laravel 13 官方 database.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/database.md#using-the-write-connection-for-reads)

### 統一將排程設定為單一伺服器執行

為了減少在多台伺服器上執行排程器時遺漏為每個任務指定 `onOneServer()` 的情況，v13.35.0 新增了 `Schedule::alwaysOnOneServer()`。在 `AppServiceProvider` 的 `boot()` 中呼叫，即可一次套用到相關的排程。

```php theme={null}
use Illuminate\Support\Facades\Schedule;

Schedule::alwaysOnOneServer();
```

這是呼叫後才會生效的預設值。沒有名稱的排程閉包不在適用範圍內，仍會在每台伺服器上執行。

> [!NOTE]
>
> `onOneServer()` 需要所有伺服器共用的中央快取。官方文件列出的支援驅動為 `database`、`memcached`、`dynamodb` 與 `redis`。僅加入設定並不會提供跨伺服器的鎖定基礎設施。

一手資料：[Run Scheduled Tasks on One Server by Default](https://laravel.com/framework/docs/changelog#october-2026-run-scheduled-tasks-on-one-server-by-default)、[Laravel 13 官方 scheduling.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/scheduling.md#running-tasks-on-one-server)。相關頁面：[任務排程](https://kawax.biz/zh-TW/scheduling.md)

### 在 Fake 中指定屬性來驗證派發

從 v13.35.0 起，可以將期望屬性的陣列傳給 Queue、Bus、Event、Notification 的 Fake。不再需要為了單純的屬性比較而每次撰寫回呼。

例如，使用具有公開 `order` 屬性的 `ShipOrder` 工作，以及測試中準備的 `$order` 時，可以這樣驗證：

```php theme={null}
use App\Jobs\ShipOrder;
use Illuminate\Support\Facades\Queue;

Queue::fake();

ShipOrder::dispatch($order);

Queue::assertPushed(ShipOrder::class, ['order' => $order]);
```

指定的屬性必須全部一致。值會進行嚴格比較，但 Eloquent 模型以 `is()` 比較，因此代表同一模型的不同實例也能比對成功。Fake 驗證的是派發，而不是工作本身的執行結果。

一手資料：[Assert Fake Dispatches by Their Properties](https://laravel.com/framework/docs/changelog#october-2026-assert-fake-dispatches-by-their-properties)、[Laravel 13 官方 queues.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/queues.md#testing)。相關頁面：[佇列](https://kawax.biz/zh-TW/queues.md)、[Mock](https://kawax.biz/zh-TW/mocking.md)

### 以比例指定 worker 的記憶體上限

從 v13.35.0 起，`queue:work` 的 `--memory` 可以指定相對於 PHP `memory_limit` 的比例。不必為每個環境重新計算固定的 MB 值，就能依照 PHP 設定調整 worker 的結束門檻。

```shell theme={null}
php artisan queue:work --memory=60%
```

這不是相對於主機或容器整體記憶體的比例。當 PHP 的 `memory_limit` 為無限制的 `-1` 時，請使用 MB 值而非比例。因達到門檻而結束的 worker 的重新啟動，交由 Supervisor 等程序監控負責。

一手資料：[Set Queue Worker Memory Limits as Percentages](https://laravel.com/framework/docs/changelog#october-2026-set-queue-worker-memory-limits-as-percentages)、[Laravel 13 官方 queues.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/queues.md#resource-considerations)

### 以專用 Content-Type 回傳 Markdown

v13.35.0 為回應工廠新增了 `markdown()`。它以 `text/markdown` 回傳 Markdown 本文，也可以指定狀態碼與額外標頭。

```php theme={null}
return response()->markdown("# Report\n\nMonthly summary", 200, [
    'Cache-Control' => 'no-store',
]);
```

可以與 `wantsMarkdown()` 等選擇回應格式的處理搭配使用。它不是將 Markdown 轉換為 HTML 回傳的功能，而是將 Markdown 本身作為回應提供的 API。

一手資料：[Return Markdown Responses](https://laravel.com/framework/docs/changelog#october-2026-return-markdown-responses)、[Laravel 13 官方 responses.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/responses.md#markdown-responses)。相關頁面：[回應](https://kawax.biz/zh-TW/responses.md)

### 在 Vitess 中以 OLAP 模式執行分析查詢

v13.36.0 為 MySQL 連線新增了 `isVitess()` 與 `olap()`。可以判斷是否正在使用 Vitess 或 PlanetScale，並以 OLAP 工作負載執行分析用途的查詢。

```php theme={null}
use Illuminate\Support\Facades\DB;

$totals = DB::connection('mysql')->olap(
    fn ($connection) => $connection->table('orders')
        ->selectRaw('customer_id, sum(total) as total')
        ->groupBy('customer_id')
        ->get()
);
```

它會為讀取與寫入兩個連線設定工作負載，並在回呼結束時恢復為 OLTP。發生例外時也會還原，在非 Vitess 的一般 MySQL 連線上，則不變更工作負載直接執行回呼。

一手資料：[Use OLAP Workloads with Vitess Connections](https://laravel.com/framework/docs/changelog#october-2026-use-olap-workloads-with-vitess-connections)、[Laravel 13 官方 database.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/database.md#running-analytical-queries-on-vitess)

### 透過 Builder 找到既有驗證規則

v13.36.0 為許多過去以字串指定的規則新增了 `Rule` 的 Builder 方法。`requiredWith()`、`acceptedIf()`、`regex()`、`timezone()` 等更容易透過 IDE 自動完成找到，並可在維持既有驗證行為的同時選擇寫法。

```php theme={null}
use Illuminate\Validation\Rule;

$rules = [
    'nickname' => [Rule::requiredWith('email'), Rule::regex('/^[a-z]+$/i')],
    'terms' => [Rule::acceptedIf('account_type', 'business')],
    'timezone' => [Rule::timezone()],
];
```

方法名稱採用 camel case。也可以與字串規則混用，因此不需要一次改寫既有規則。

一手資料：[Discover More Validation Rules Through Builders](https://laravel.com/framework/docs/changelog#october-2026-discover-more-validation-rules-through-builders)、[Laravel 13 官方 validation.md](https://github.com/laravel/docs/blob/f7a20c401a30827991659174d48d958f92517a9e/validation.md#rule-builders)。相關頁面：[Validation](https://kawax.biz/zh-TW/validation.md)

## Laravel Cloud

官方月度部落格介紹了以下 3 個項目。

| 功能 | 更新內容 |
| - | - |
| Resend 整合 | 將 Resend 帳戶連接到組織後，會匯入寄件網域，並顯示所需的 DNS 紀錄與驗證狀態。將郵件資源連接到環境後，Cloud 會核發 API 金鑰，並設定 `RESEND_API_KEY`、`MAIL_MAILER`、`MAIL_FROM_ADDRESS` 與 `MAIL_FROM_NAME`。 |
| Cloud scheduler | Cloud 支援的各語言應用程式，無需安裝 cron 或常駐排程器程序，即可執行定期指令。可以使用預設或自訂 cron 表達式，並在 Logs 中查看執行結果的輸出、結束碼與耗時。 |
| 網域健康檢查 | 每小時確認已連接網域的 DNS 是否指向 Cloud，以及 SSL 憑證的更新狀態。問題會顯示在環境畫布上，並透過郵件與 Slack 通知。 |

一手資料：[Laravel October Product Updates — Laravel Cloud](https://laravel.com/blog/laravel-october-product-updates#laravel-cloud)、[Laravel Cloud changelog](https://laravel.com/cloud/docs/changelog)。相關頁面：[Laravel Cloud 介紹](https://kawax.biz/zh-TW/blog/laravel-cloud.md)

## Laravel Forge

* **PHP 安全更新通知**：依伺服器顯示受 10 月 PHP 安全發布影響的版本，並提示修正版本的提供狀況。可以透過 **Recheck versions** 重新確認實際安裝的版本。重新確認顯示與更新 PHP 是不同的操作。
* **佈建失敗的處理**：將無法完成的伺服器顯示為失敗狀態，並提供通知、後續操作指引與刪除操作。PHP 與 Nginx 的安裝也會在確定失敗前重試。

月度部落格也提到發布了回顧 10 月 PHP 與 Node.js 安全應對的 Post-mortem。具體應對內容與更新判斷，請參閱官方說明。

一手資料：[Laravel October Product Updates — Laravel Forge](https://laravel.com/blog/laravel-october-product-updates#laravel-forge)、[Laravel Forge changelog](https://laravel.com/forge/docs/changelog)

## 相關文章

> [card] [2026 年 9 月更新](https://kawax.biz/zh-TW/blog/changelog/202609.md)
>
> 回顧執行時建構 AI 提供者、搜尋擴充、Mercure 以及 Cloud 的隔離預覽環境。

> [card] [資料庫指南](https://kawax.biz/zh-TW/database.md)
>
> 確認讀寫分離與資料庫連線的基礎。


## Related topics

- [2026 年 9 月 Laravel 更新](https://kawax.biz/zh-TW/blog/changelog/202609.md)
- [2026 年 3 月 Laravel 更新](https://kawax.biz/zh-TW/blog/changelog/202603.md)
- [2026 年 4 月 Laravel 更新](https://kawax.biz/zh-TW/blog/changelog/202604.md)
- [2026 年 5 月 Laravel 更新](https://kawax.biz/zh-TW/blog/changelog/202605.md)
- [2026 年 6 月 Laravel 更新](https://kawax.biz/zh-TW/blog/changelog/202606.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.