> ## 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 年 4 月 Laravel 更新

> 2026 年 4 月 Laravel 生態系更新。Passkeys（無密碼認證）、Debounceable Jobs、MCP UI App、Redis Cluster 支援等。

2026 年 4 月，全端無密碼認證成為 Laravel 標準功能，並新增了控制爆量 Job 派送的 Debounceable Job、MCP UI App 支援等眾多實用功能。

參考來源：[Laravel April Product Updates](https://laravel.com/blog/laravel-april-product-updates)

***

## Laravel Framework

### Debounceable Queued Jobs

針對爆量工作負載的乾淨解決方案。使用 `#[DebounceFor]` 屬性，可將指定時間內的多次 dispatch 合而為一，只執行最後一次。與 `ShouldBeUnique` 相反的思路，用來高效處理去抖動視窗內的連續更新。

```php theme={null}
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\Attributes\DebounceFor;

#[DebounceFor(30)]
class RebuildSearchIndex implements ShouldQueue
{
    // 就算使用者在 30 秒內更新文件 10 次，
    // 索引重建也只會執行 1 次
}

// 呼叫端也能進行 debounce（不需修改類別）
RebuildSearchIndex::dispatch()->debounceFor(seconds: 30);
```

<Info>
  被 debounce 掉的 Job 會發出 `JobDebounced` 事件，因此可以將被略過的 Job 可視化。
</Info>

### 健康路由的 JSON 回應支援

在僅提供 API 的應用中，再也不需要從 `/up` 抓取 HTML。內建的健康路由對 JSON 請求會回傳 JSON。

```json theme={null}
{ "status": "Application is up" }
```

與負載平衡器、Uptime 監控、Orchestrator 的整合變得更簡單，且不需要更改任何設定。

### JsonFormatter

透過 `JsonFormatter`，自訂例外的 `context()` 資料可確實地被記錄到結構化紀錄中，並包含例外鏈中前一個例外的 context。

```php theme={null}
// config/logging.php
'formatter' => Illuminate\Log\Formatters\JsonFormatter::class,
```

### prefersJsonResponses()

在 API 應用中只要於 `bootstrap/app.php` 加一行，就能將較寬鬆的 `Accept` 標頭當作 JSON 處理，讓認證重新導向、驗證錯誤、例外頁面能為 client 適當地序列化。

```php theme={null}
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(...)
    ->prefersJsonResponses()
    ->create();
```

### Cloudflare Email Service 支援

Cloudflare 的 Email Service 正式支援作為 Laravel Mailer。

```php theme={null}
// config/services.php
'cloudflare' => [
    'account_id' => env('CLOUDFLARE_ACCOUNT_ID'),
    'token' => env('CLOUDFLARE_TOKEN'),
],
```

### 完整支援 Redis Cluster

在 AWS ElastiCache Serverless 等 Redis Cluster 環境中的 CROSSSLOT 錯誤已修正。當 Laravel 的佇列、ConcurrencyLimiter 偵測到 Cluster 連線時，會自動用 hash tag 包住佇列名稱。

```
queues:{default}          # "default" slot
queues:{default}:delayed  # 相同 slot
queues:{default}:reserved # 相同 slot
```

### Queue Job 檢查方法

新增 3 個方法，可不直接查看 DB 就確認 Job 內容。

```php theme={null}
Queue::pendingJobs();   // 等待中的 Job
Queue::delayedJobs();   // 延遲的 Job
Queue::reservedJobs();  // 處理中的 Job

// 可存取 InspectedJob 實例
Queue::reservedJobs('high-priority')->first()->name;
// => 'App\Jobs\SendEmail'
```

### Form Request Strict Mode

可控制未宣告的欄位不得通過驗證。在 `rules()` 中未宣告的接收欄位會導致驗證失敗。

```php theme={null}
// AppServiceProvider
public function boot(): void
{
    FormRequest::failOnUnknownFields(! app()->isProduction());
}
```

***

## Passkeys（無密碼認證）

無密碼認證已在整個 First-party 堆疊中實現。

* **`laravel/passkeys`（伺服器端）**：提供 migration、登入／確認／憑證管理路由、WebAuthn 動作與事件
* **`@laravel/passkeys`（用戶端）**：以 React、Vue、Svelte 各自的 helper 處理瀏覽器的 WebAuthn 儀式
* **Fortify 整合**：只要用 `Features::passkeys()` 啟用，Fortify 應用即可使用相同的端點與契約

```php theme={null}
// config/fortify.php
'features' => [
    Features::passkeys(),
],
```

***

## MCP UI App 支援

MCP Tool 除了純文字，也能在 iframe 內渲染完整沙箱化的 HTML App。

```bash theme={null}
php artisan make:mcp-app-resource DashboardApp
```

```php theme={null}
class DashboardApp extends AppResource
{
    #[RendersApp]
    public function handle(Request $request): Response
    {
        return Response::view('mcp.dashboard-app', [
            'title' => 'Dashboard',
        ]);
    }
}
```

***

## Inertia 與生態系

* **`useHttp` hook**：新增 `onHttpException`、`onNetworkError` callback
* **Laravel Echo Svelte 5 adapter**：可透過 `useEcho` rune 從 Svelte 使用即時功能
* **Dusk**：`clickOnceEnabled()`、`clickOnceVisible()` 防止不穩定的測試
* **Horizon**：完整支援 Redis Cluster（支援 AWS ElastiCache Serverless）
* **VS Code 擴充**：支援 Laravel 13 新屬性的自動完成、hover、導覽

***

## Laravel Cloud、Laravel Forge

| 產品                | 主要更新                                                    |
| ----------------- | ------------------------------------------------------- |
| **Laravel Cloud** | 支援行動裝置的全響應式 UI、強化邊緣網路（顯示 top IP／路徑、Firewall／Cache 規則轉換） |
| **Laravel Forge** | 支援 PHP 8.5、多 SSL 伺服器支援、憑證更新警示                           |


## Related topics

- [2026 年 3 月 Laravel 更新](/zh-TW/blog/changelog/202603.md)
- [2026 年 5 月 Laravel 更新](/zh-TW/blog/changelog/202605.md)
- [2026 年 6 月 Laravel 更新](/zh-TW/blog/changelog/202606.md)
- [Laravel 新程式碼分析生態系 — surveyor / ranger / roster](/zh-TW/blog/laravel-ecosystem-analysis.md)
- [Laravel 13 新功能彙總](/zh-TW/blog/laravel-13-new-features.md)
