Skip to content

Laravel Boost

簡介

Laravel Boost 透過提供關鍵的指引與 Agent 技能來加速 AI 輔助開發,協助 AI Agent 編寫符合 Laravel 最佳實踐的高品質 Laravel 應用程式。

Boost 還提供了一個強大的 Laravel 生態系統文件 API,它結合了內建的 MCP 工具與包含超過 17,000 條 Laravel 特定資訊的龐大知識庫,並透過 Embedding (嵌入) 的語義搜尋功能進行強化,以提供精確且具備上下文關聯的結果。Boost 會指示如 Claude Code 和 Cursor 等 AI Agent 使用此 API 來學習最新的 Laravel 功能與最佳實踐。

安裝

Laravel Boost 可以透過 Composer 安裝:

shell
composer require laravel/boost --dev

接著,安裝 MCP 伺服器與編碼指引:

shell
php artisan boost:install

boost:install 指令將會為您在安裝過程中選擇的編碼 Agent 產生相關的 Agent 指引與技能檔案。

一旦安裝好 Laravel Boost,您就可以準備使用 Cursor、Claude Code 或您選擇的 AI Agent 開始編碼了。

📌 備註

您可以隨意將產生的 MCP 設定檔 (.mcp.json)、指引檔案 (CLAUDE.md, AGENTS.md, junie/ 等) 以及 boost.json 設定檔加入到應用程式的 .gitignore 中,因為這些檔案在執行 boost:installboost:update 時會自動重新產生。

設定您的 Agent

text
1. Open the command palette (`Cmd+Shift+P` or `Ctrl+Shift+P`)
2. Press `enter` on "/open MCP Settings"
3. Turn the toggle on for `laravel-boost`
text
Claude Code support is typically enabled automatically. If you find it isn't, open a shell in the project's directory and run the following command:

claude mcp add -s local -t stdio laravel-boost php artisan boost:mcp
text
Codex support is typically enabled automatically. If you find it isn't, open a shell in the project's directory and run the following command:

codex mcp add laravel-boost -- php "artisan" "boost:mcp"
text
Gemini CLI support is typically enabled automatically. If you find it isn't, open a shell in the project's directory and run the following command:

gemini mcp add -s project -t stdio laravel-boost php artisan boost:mcp
text
1. Open the command palette (`Cmd+Shift+P` or `Ctrl+Shift+P`)
2. Press `enter` on "MCP: List Servers"
3. Arrow to `laravel-boost` and press `enter`
4. Choose "Start server"
text
1. Press `shift` twice to open the command palette
2. Search "MCP Settings" and press `enter`
3. Check the box next to `laravel-boost`
4. Click "Apply" at the bottom right

保持 Boost 資源更新

您可能需要定期更新本地的 Boost 資源 (AI 指引與技能),以確保它們反映了您已安裝的 Laravel 生態系統套件之最新版本。為此,您可以使用 boost:update Artisan 指令。

shell
php artisan boost:update

您也可以透過將其加入 Composer 的 "post-update-cmd" 腳本中來自動化此過程:

json
{
  "scripts": {
    "post-update-cmd": [
      "@php artisan boost:update --ansi"
    ]
  }
}

MCP 伺服器

Laravel Boost 提供了一個 MCP (Model Context Protocol) 伺服器,它向 AI Agent 公開了用於與您的 Laravel 應用程式互動的工具。這些工具讓 Agent 能夠檢查應用程式結構、查詢資料庫、執行程式碼等等。

可用的 MCP 工具

名稱備註
Application Info讀取 PHP 與 Laravel 版本、資料庫引擎、包含版本的生態系統套件清單,以及 Eloquent 模型
Browser Logs讀取來自瀏覽器的日誌與錯誤
Database Connections檢查可用的資料庫連線,包含預設連線
Database Query對資料庫執行查詢
Database Schema讀取資料庫綱要 (Schema)
Get Absolute URL將相對路徑 URI 轉換為絕對路徑,以便 Agent 產生有效的 URL
Last Error從應用程式的日誌檔案中讀取最後一個錯誤
Read Log Entries讀取最後 N 筆日誌項目
Search Docs查詢 Laravel 託管的文件 API 服務,以根據安裝的套件檢索文件

手動註冊 MCP 伺服器

有時您可能需要向您選擇的編輯器手動註冊 Laravel Boost MCP 伺服器。您應該使用以下詳細資訊註冊 MCP 伺服器:

指令php
參數artisan boost:mcp

JSON 範例:

json
{
    "mcpServers": {
        "laravel-boost": {
            "command": "php",
            "args": ["artisan", "boost:mcp"]
        }
    }
}

AI 指南

AI 指南是組合式的指令檔案,會預先載入以為 AI Agent 提供有關 Laravel 生態系統套件的重要上下文。這些指南包含核心慣例、最佳實踐以及框架特定模式,幫助 Agent 生成一致且高品質的程式碼。

可用的 AI 指南

Laravel Boost 包含以下套件與框架的 AI 指南。core 指南為特定套件提供通用且廣泛的 AI 建議,適用於所有版本。

套件支援版本
Core & Boostcore
Laravel Frameworkcore, 10.x, 11.x, 12.x
Livewirecore, 2.x, 3.x, 4.x
Flux UIcore, free, pro
Foliocore
Herdcore
Inertia Laravelcore, 1.x, 2.x, 3.x
Inertia Reactcore, 1.x, 2.x, 3.x
Inertia Vuecore, 1.x, 2.x, 3.x
Inertia Sveltecore, 1.x, 2.x, 3.x
MCPcore
Pennantcore
Pestcore, 3.x, 4.x
PHPUnitcore
Pintcore
Sailcore
Tailwind CSScore, 3.x, 4.x
Livewire Voltcore
Wayfindercore
Enforce Testsconditional

注意: 若要保持您的 AI 指南更新,請參閱 保持 Boost 資源更新 章節。

新增自訂 AI 指南

若要使用您自訂的 AI 指南來擴充 Laravel Boost,請將 .blade.php.md 檔案新增到應用程式的 .ai/guidelines/* 目錄中。當您執行 boost:install 時,這些檔案將自動包含在 Laravel Boost 的指南中。

覆蓋 Boost AI 指南

您可以透過建立具有相符檔案路徑的自訂指南,來覆蓋 Boost 內建的 AI 指南。當您建立一個與現有 Boost 指南路徑相符的自訂指南時,Boost 將使用您的自訂版本而非內建版本。

例如,要覆蓋 Boost 的 "Inertia React v2 Form Guidance" 指南,請在 .ai/guidelines/inertia-react/2/forms.blade.php 建立檔案。當您執行 boost:install 時,Boost 將包含您的自訂指南而非預設指南。

第三方套件 AI 指南

如果您維護一個第三方套件並希望 Boost 包含該套件的 AI 指南,您可以在套件中新增 resources/boost/guidelines/core.blade.php 檔案來實現。當您套件的使用者執行 php artisan boost:install 時,Boost 將自動載入您的指南。

AI 指南應提供套件功能的簡短概覽,概述任何必要的檔案結構或慣例,並說明如何建立或使用其主要功能(附上範例指令或程式碼片段)。請保持內容簡潔、具可操作性並專注於最佳實踐,以便 AI 能為您的使用者生成正確的程式碼。以下是一個範例:

php
## Package Name

This package provides [brief description of functionality].

### Features

- Feature 1: [clear & short description].
- Feature 2: [clear & short description]. Example usage:

@verbatim
<code-snippet name="How to use Feature 2" lang="php">
$result = PackageName::featureTwo($param1, $param2);
</code-snippet>
@endverbatim

Agent 技能

Agent 技能 是輕量化、具針對性的知識模組,Agent 在處理特定領域時可以依需求啟用。與預先載入的指南不同,技能允許僅在相關時才載入詳細的模式和最佳實踐,從而減少上下文膨脹並提高 AI 生成程式碼的相關性。

當您執行 boost:install 並選擇技能作為功能時,系統會根據在 composer.json 中偵測到的套件自動安裝技能。例如,如果您的專案包含 livewire/livewire,則會自動安裝 livewire-development 技能。

可用的技能

技能套件
fluxui-developmentFlux UI
folio-routingFolio
inertia-react-developmentInertia React
inertia-svelte-developmentInertia Svelte
inertia-vue-developmentInertia Vue
livewire-developmentLivewire
mcp-developmentMCP
pennant-developmentPennant
pest-testingPest
tailwindcss-developmentTailwind CSS
volt-developmentVolt
wayfinder-developmentWayfinder

注意: 若要保持您的技能更新,請參閱 保持 Boost 資源更新 章節。

自訂技能

要建立您自己的自訂技能,請將 SKILL.md 檔案新增到應用程式的 .ai/skills/{skill-name}/ 目錄中。當您執行 boost:update 時,您的自訂技能將與 Boost 的內建技能一起安裝。

例如,為您應用程式的領域邏輯建立一個自訂技能:

unknown
.ai/skills/creating-invoices/SKILL.md

覆蓋技能

您可以透過建立具有相符名稱的自訂技能,來覆蓋 Boost 內建的技能。當您建立一個與現有 Boost 技能名稱相符的自訂技能時,Boost 將使用您的自訂版本而非內建版本。

例如,要覆蓋 Boost 的 livewire-development 技能,請在 .ai/skills/livewire-development/SKILL.md 建立檔案。當您執行 boost:update 時,Boost 將包含您的自訂技能而非預設技能。

第三方套件技能

如果您維護一個第三方套件並希望 Boost 包含該套件的技能,您可以在套件中新增 resources/boost/skills/{skill-name}/SKILL.md 檔案來實現。當您套件的使用者執行 php artisan boost:install 時,Boost 將根據使用者偏好自動安裝您的技能。

Boost 技能支援 Agent Skills 格式,且應結構化為一個包含 SKILL.md 檔案的資料夾,該檔案需具備 YAML Frontmatter 和 Markdown 指令。SKILL.md 檔案必須包含必要的 Frontmatter(namedescription),並可以選擇性包含腳本、模板和參考資料。

技能應概述任何必要的檔案結構或慣例,並說明如何建立或使用其主要功能(附上範例指令或程式碼片段)。請保持內容簡潔、具可操作性並專注於最佳實踐,以便 AI 能為您的使用者生成正確的程式碼:

markdown
---
name: package-name-development
description: Build and work with PackageName features, including components and workflows.
---

# Package Name Development

## When to use this skill
Use this skill when working with PackageName features...

## Features

- Feature 1: [clear & short description].
- Feature 2: [clear & short description]. Example usage:

$result = PackageName::featureTwo($param1, $param2);

指南 vs. 技能

Laravel Boost 提供了兩種不同的方式來為 AI agent 提供關於應用程式的上下文:指南 (guidelines)技能 (skills)

指南 (Guidelines) 在 AI agent 啟動時預先載入,提供關於 Laravel 慣例與最佳實踐的基礎上下文,並廣泛地套用於您的程式碼庫。

技能 (Skills) 在處理特定任務時按需啟動,包含特定領域(如 Livewire 元件或 Pest 測試)的詳細模式。僅在相關時載入技能可減少上下文膨脹並提升程式碼品質。

面向指南技能
載入時機預先載入,始終存在按需載入,相關時觸發
範圍廣泛且基礎聚焦且針對特定任務
目的核心慣例與最佳實踐詳細的實作模式

文件 API

Laravel Boost 包含一個文件 API,為 AI agent 提供對包含超過 17,000 條 Laravel 特定資訊的廣泛知識庫的存取權限。此 API 使用帶有嵌入 (embeddings) 的語義搜尋來提供精確且具備上下文感知的結果。

Search Docs MCP 工具允許 agent 查詢 Laravel 代管的文件 API 服務,以根據您安裝的套件檢索文件。Boost 的 AI 指南和技能將自動引導您的開發 agent 使用此 API。

套件支援版本
Laravel Framework10.x, 11.x, 12.x
Filament2.x, 3.x, 4.x, 5.x
Flux UI2.x Free, 2.x Pro
Inertia1.x, 2.x
Livewire1.x, 2.x, 3.x, 4.x
Nova4.x, 5.x
Pest3.x, 4.x
Tailwind CSS3.x, 4.x

擴充 Boost

Boost 開箱即用支援許多熱門的 IDE 與 AI agent。如果您的開發工具尚未受到支援,您可以建立自己的 agent 並將其與 Boost 整合。

增加對其他 IDE / AI Agent 的支援

若要增加對新 IDE 或 AI agent 的支援,請建立一個繼承 Laravel\Boost\Install\Agents\Agent 的類別,並根據您的需求實作下列一或多個合約 (contracts):

  • Laravel\Boost\Contracts\SupportsGuidelines - 增加對 AI 指南的支援。
  • Laravel\Boost\Contracts\SupportsMcp - 增加對 MCP 的支援。
  • Laravel\Boost\Contracts\SupportsSkills - 增加對 Agent 技能的支援。

撰寫 Agent

php
<?php

declare(strict_types=1);

namespace App;

use Laravel\Boost\Contracts\SupportsGuidelines;
use Laravel\Boost\Contracts\SupportsMcp;
use Laravel\Boost\Contracts\SupportsSkills;
use Laravel\Boost\Install\Agents\Agent;

class CustomAgent extends Agent implements SupportsGuidelines, SupportsMcp, SupportsSkills
{
    // Your implementation...
}

有關實作範例,請參考 ClaudeCode.php

註冊 Agent

在應用程式的 App\Providers\AppServiceProviderboot 方法中註冊您的自訂 agent:

php
use Laravel\Boost\Boost;

public function boot(): void
{
    Boost::registerAgent('customagent', CustomAgent::class);
}

一旦註冊完成,您的 agent 在執行 php artisan boost:install 時將可供選擇。