refactor: susun semula struktur folder — Laravel source ke src/
This commit is contained in:
143
vendor/laravel/boost/src/Mcp/Boost.php
vendored
Normal file
143
vendor/laravel/boost/src/Mcp/Boost.php
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp;
|
||||
|
||||
use Laravel\Boost\Mcp\Methods\CallToolWithExecutor;
|
||||
use Laravel\Boost\Mcp\Prompts\LaravelCodeSimplifier\LaravelCodeSimplifier;
|
||||
use Laravel\Boost\Mcp\Prompts\UpgradeInertiav3\UpgradeInertiaV3;
|
||||
use Laravel\Boost\Mcp\Prompts\UpgradeLaravelv13\UpgradeLaravelV13;
|
||||
use Laravel\Boost\Mcp\Prompts\UpgradeLivewirev4\UpgradeLivewireV4;
|
||||
use Laravel\Boost\Mcp\Tools\ApplicationInfo;
|
||||
use Laravel\Boost\Mcp\Tools\BrowserLogs;
|
||||
use Laravel\Boost\Mcp\Tools\DatabaseConnections;
|
||||
use Laravel\Boost\Mcp\Tools\DatabaseQuery;
|
||||
use Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
use Laravel\Boost\Mcp\Tools\GetAbsoluteUrl;
|
||||
use Laravel\Boost\Mcp\Tools\LastError;
|
||||
use Laravel\Boost\Mcp\Tools\ReadLogEntries;
|
||||
use Laravel\Boost\Mcp\Tools\SearchDocs;
|
||||
use Laravel\Mcp\Server;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
use Laravel\Mcp\Server\Resource;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
|
||||
class Boost extends Server
|
||||
{
|
||||
/**
|
||||
* The MCP server's name.
|
||||
*/
|
||||
protected string $name = 'Laravel Boost';
|
||||
|
||||
/**
|
||||
* The MCP server's version.
|
||||
*/
|
||||
protected string $version = '0.0.1';
|
||||
|
||||
/**
|
||||
* The MCP server's instructions for the LLM.
|
||||
*/
|
||||
protected string $instructions = 'Laravel ecosystem MCP server offering database schema access, error logs, semantic documentation search and more. Boost helps with code generation.';
|
||||
|
||||
/**
|
||||
* The default pagination length for resources that support pagination.
|
||||
*/
|
||||
public int $defaultPaginationLength = 50;
|
||||
|
||||
/**
|
||||
* The tools registered with this MCP server.
|
||||
*
|
||||
* @var array<int, class-string<Tool>>
|
||||
*/
|
||||
protected array $tools = [];
|
||||
|
||||
/**
|
||||
* The resources registered with this MCP server.
|
||||
*
|
||||
* @var array<int, class-string<Resource>>
|
||||
*/
|
||||
protected array $resources = [];
|
||||
|
||||
/**
|
||||
* The prompts registered with this MCP server.
|
||||
*
|
||||
* @var array<int, class-string<Prompt>>
|
||||
*/
|
||||
protected array $prompts = [];
|
||||
|
||||
protected function boot(): void
|
||||
{
|
||||
$this->tools = $this->discoverTools();
|
||||
$this->resources = $this->discoverResources();
|
||||
$this->prompts = $this->discoverPrompts();
|
||||
|
||||
// Override the tools/call method to use our ToolExecutor
|
||||
$this->methods['tools/call'] = CallToolWithExecutor::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, class-string<Tool>>
|
||||
*/
|
||||
protected function discoverTools(): array
|
||||
{
|
||||
return $this->filterPrimitives([
|
||||
ApplicationInfo::class,
|
||||
BrowserLogs::class,
|
||||
DatabaseConnections::class,
|
||||
DatabaseQuery::class,
|
||||
DatabaseSchema::class,
|
||||
GetAbsoluteUrl::class,
|
||||
LastError::class,
|
||||
ReadLogEntries::class,
|
||||
SearchDocs::class,
|
||||
], 'tools');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, class-string<Resource>>
|
||||
*/
|
||||
protected function discoverResources(): array
|
||||
{
|
||||
return $this->filterPrimitives([
|
||||
Resources\ApplicationInfo::class,
|
||||
], 'resources');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, class-string<Prompt>>
|
||||
*/
|
||||
protected function discoverPrompts(): array
|
||||
{
|
||||
return $this->filterPrimitives([
|
||||
LaravelCodeSimplifier::class,
|
||||
UpgradeInertiaV3::class,
|
||||
UpgradeLaravelV13::class,
|
||||
UpgradeLivewireV4::class,
|
||||
], 'prompts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, Tool|Resource|Prompt|class-string> $availablePrimitives
|
||||
* @return array<int, Tool|Resource|Prompt|class-string>
|
||||
*/
|
||||
private function filterPrimitives(array $availablePrimitives, string $type): array
|
||||
{
|
||||
$excludeList = config("boost.mcp.{$type}.exclude", []);
|
||||
$includeList = config("boost.mcp.{$type}.include", []);
|
||||
|
||||
$filtered = collect($availablePrimitives)->reject(function (string|object $item) use ($excludeList): bool {
|
||||
$className = is_string($item) ? $item : $item::class;
|
||||
|
||||
return in_array($className, $excludeList, true);
|
||||
});
|
||||
|
||||
$explicitlyIncluded = collect($includeList)
|
||||
->filter(fn (string $class): bool => class_exists($class));
|
||||
|
||||
return $filtered
|
||||
->merge($explicitlyIncluded)
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
67
vendor/laravel/boost/src/Mcp/Methods/CallToolWithExecutor.php
vendored
Normal file
67
vendor/laravel/boost/src/Mcp/Methods/CallToolWithExecutor.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Methods;
|
||||
|
||||
use Laravel\Boost\Mcp\ToolExecutor;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Contracts\Errable;
|
||||
use Laravel\Mcp\Server\Contracts\Method;
|
||||
use Laravel\Mcp\Server\Exceptions\JsonRpcException;
|
||||
use Laravel\Mcp\Server\Methods\Concerns\InteractsWithResponses;
|
||||
use Laravel\Mcp\Server\ServerContext;
|
||||
use Laravel\Mcp\Server\Transport\JsonRpcRequest;
|
||||
use Laravel\Mcp\Server\Transport\JsonRpcResponse;
|
||||
use Throwable;
|
||||
|
||||
class CallToolWithExecutor implements Errable, Method
|
||||
{
|
||||
use InteractsWithResponses;
|
||||
|
||||
public function __construct(protected ToolExecutor $executor)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the JSON-RPC tool/call request with process isolation.
|
||||
*/
|
||||
public function handle(JsonRpcRequest $request, ServerContext $context): JsonRpcResponse
|
||||
{
|
||||
if (is_null($request->get('name'))) {
|
||||
throw new JsonRpcException(
|
||||
'Missing [name] parameter.',
|
||||
-32602,
|
||||
$request->id,
|
||||
);
|
||||
}
|
||||
|
||||
$tool = $context
|
||||
->tools()
|
||||
->first(
|
||||
fn ($tool): bool => $tool->name() === $request->params['name'],
|
||||
fn () => throw new JsonRpcException(
|
||||
"Tool [{$request->params['name']}] not found.",
|
||||
-32602,
|
||||
$request->id,
|
||||
));
|
||||
|
||||
$arguments = [];
|
||||
|
||||
if (isset($request->params['arguments']) && is_array($request->params['arguments'])) {
|
||||
$arguments = $request->params['arguments'];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->executor->execute($tool::class, $arguments);
|
||||
} catch (Throwable $throwable) {
|
||||
$response = Response::error('Tool execution error: '.$throwable->getMessage());
|
||||
}
|
||||
|
||||
return $this->toJsonRpcResponse($request, $response, fn ($responseFactory): array => [
|
||||
'content' => $responseFactory->responses()->map(fn ($response) => $response->content()->toTool($tool))->all(),
|
||||
'isError' => $responseFactory->responses()->contains(fn ($response) => $response->isError()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
0
vendor/laravel/boost/src/Mcp/Prompts/.gitkeep
vendored
Normal file
0
vendor/laravel/boost/src/Mcp/Prompts/.gitkeep
vendored
Normal file
27
vendor/laravel/boost/src/Mcp/Prompts/LaravelCodeSimplifier/LaravelCodeSimplifier.php
vendored
Normal file
27
vendor/laravel/boost/src/Mcp/Prompts/LaravelCodeSimplifier/LaravelCodeSimplifier.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Prompts\LaravelCodeSimplifier;
|
||||
|
||||
use Laravel\Boost\Concerns\RendersBladeGuidelines;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
|
||||
class LaravelCodeSimplifier extends Prompt
|
||||
{
|
||||
use RendersBladeGuidelines;
|
||||
|
||||
protected string $name = 'laravel-code-simplifier';
|
||||
|
||||
protected string $title = 'laravel_code_simplifier';
|
||||
|
||||
protected string $description = 'Simplifies and refines PHP/Laravel code for clarity, consistency, and maintainability while preserving all functionality. Focuses on recently modified code unless instructed otherwise.';
|
||||
|
||||
public function handle(): Response
|
||||
{
|
||||
$content = $this->renderBladeFile(__DIR__.'/laravel-code-simplifier.blade.php');
|
||||
|
||||
return Response::text($content);
|
||||
}
|
||||
}
|
||||
66
vendor/laravel/boost/src/Mcp/Prompts/LaravelCodeSimplifier/laravel-code-simplifier.blade.php
vendored
Normal file
66
vendor/laravel/boost/src/Mcp/Prompts/LaravelCodeSimplifier/laravel-code-simplifier.blade.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
# Laravel Code Simplifier
|
||||
|
||||
You are an expert PHP/Laravel code simplification specialist focused on enhancing code clarity, consistency, and maintainability while preserving exact functionality. Your expertise lies in applying Laravel best practices and standards to simplify and improve code without altering its behavior. You prioritize readable, explicit code over overly compact solutions. This is a balance that you have mastered as a result of your years as an expert PHP developer.
|
||||
|
||||
You will analyze recently modified code using git and apply refinements that:
|
||||
|
||||
## 1. Preserve Functionality
|
||||
|
||||
Never change what the code does - only how it does it. All original features, outputs, and behaviors must remain intact.
|
||||
|
||||
## 2. Apply Project Standards
|
||||
|
||||
Follow established project coding standards including:
|
||||
|
||||
- Use proper namespace declarations and organize imports logically
|
||||
- Prefer explicit return type declarations on methods
|
||||
- Follow Laravel conventions for controllers, models, and services
|
||||
- Use proper error handling patterns (exceptions, custom exception classes)
|
||||
- Maintain consistent naming conventions (PSR-12, Laravel standards)
|
||||
|
||||
## 3. Enhance Clarity
|
||||
|
||||
Simplify the code structure by:
|
||||
|
||||
- Reducing unnecessary complexity and nesting
|
||||
- Eliminating redundant code and abstractions
|
||||
- Improving readability through clear variable and function names
|
||||
- Consolidating related logic
|
||||
- Removing unnecessary comments that describe obvious code
|
||||
- **IMPORTANT**: Avoid nested ternary operators - prefer match expressions, switch statements, or if/else chains for multiple conditions
|
||||
- Choose clarity over brevity - explicit code is often better than overly compact code
|
||||
|
||||
## 4. Maintain Balance
|
||||
|
||||
Avoid oversimplification that could:
|
||||
|
||||
- Reduce code clarity or maintainability
|
||||
- Create overly clever solutions that are hard to understand
|
||||
- Combine too many concerns into single methods or classes
|
||||
- Remove helpful abstractions that improve code organization
|
||||
- Prioritize "fewer lines" over readability (e.g., nested ternaries, dense one-liners)
|
||||
- Make the code harder to debug or extend
|
||||
|
||||
## 5. Focus Scope
|
||||
|
||||
Only refine code that has been recently modified or touched in the current session, unless explicitly instructed to review a broader scope.
|
||||
|
||||
## Refinement Process
|
||||
|
||||
1. Identify the recently modified code sections
|
||||
2. Analyze for opportunities to improve elegance and consistency
|
||||
3. Apply project-specific best practices and coding standards
|
||||
4. Ensure all functionality remains unchanged
|
||||
5. Verify the refined code is simpler and more maintainable
|
||||
6. Document only significant changes that affect understanding
|
||||
|
||||
## Execution Strategy
|
||||
|
||||
When multiple files need refinement, maximize efficiency by:
|
||||
|
||||
- **Spin up background agents in parallel** to process independent files simultaneously
|
||||
- Each agent should handle a separate file or logical unit of work
|
||||
- Coordinate results to ensure consistency across related files
|
||||
- Use as many concurrent agents as possible when files don't have dependencies on each other
|
||||
|
||||
You operate autonomously and proactively, refining code immediately after it's written or modified without requiring explicit requests. Your goal is to ensure all code meets the highest standards of elegance and maintainability while preserving its complete functionality.
|
||||
52
vendor/laravel/boost/src/Mcp/Prompts/UpgradeInertiav3/UpgradeInertiaV3.php
vendored
Normal file
52
vendor/laravel/boost/src/Mcp/Prompts/UpgradeInertiav3/UpgradeInertiaV3.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Prompts\UpgradeInertiav3;
|
||||
|
||||
use Laravel\Boost\Concerns\RendersBladeGuidelines;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
use Laravel\Roster\Enums\Packages;
|
||||
use Laravel\Roster\Roster;
|
||||
|
||||
class UpgradeInertiaV3 extends Prompt
|
||||
{
|
||||
use RendersBladeGuidelines;
|
||||
|
||||
protected string $name = 'upgrade-inertia-v3';
|
||||
|
||||
protected string $title = 'upgrade_inertia_v3';
|
||||
|
||||
protected string $description = 'Provides step-by-step guidance for upgrading from Inertia v2 to v3.';
|
||||
|
||||
public function shouldRegister(Roster $roster): bool
|
||||
{
|
||||
if ($roster->uses(Packages::INERTIA_LARAVEL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($roster->uses(Packages::INERTIA_REACT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($roster->uses(Packages::INERTIA_VUE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $roster->uses(Packages::INERTIA_SVELTE);
|
||||
}
|
||||
|
||||
public function handle(): Response
|
||||
{
|
||||
$roster = $this->getGuidelineAssist()->roster;
|
||||
|
||||
$content = $this->renderBladeFile(__DIR__.'/upgrade-inertia-v3.blade.php', [
|
||||
'usesReact' => $roster->uses(Packages::INERTIA_REACT),
|
||||
'usesVue' => $roster->uses(Packages::INERTIA_VUE),
|
||||
'usesSvelte' => $roster->uses(Packages::INERTIA_SVELTE),
|
||||
]);
|
||||
|
||||
return Response::text($content);
|
||||
}
|
||||
}
|
||||
408
vendor/laravel/boost/src/Mcp/Prompts/UpgradeInertiav3/upgrade-inertia-v3.blade.php
vendored
Normal file
408
vendor/laravel/boost/src/Mcp/Prompts/UpgradeInertiav3/upgrade-inertia-v3.blade.php
vendored
Normal file
@@ -0,0 +1,408 @@
|
||||
# Inertia v2 to v3 Upgrade Specialist
|
||||
|
||||
You are an expert Inertia upgrade specialist with deep knowledge of both Inertia v2 and v3. Your task is to systematically upgrade the application from Inertia v2 to v3 while ensuring all functionality remains intact. You understand the nuances of breaking changes and can identify affected code patterns with precision.
|
||||
|
||||
## Core Principle: Documentation-First Approach
|
||||
|
||||
**IMPORTANT:** Always use the `search-docs` tool whenever you need:
|
||||
- Specific code examples for implementing Inertia v3 features
|
||||
- Clarification on breaking changes or new syntax
|
||||
- Verification of upgrade patterns before applying them
|
||||
- Examples of correct usage for new directives or methods
|
||||
|
||||
The official Inertia documentation is your primary source of truth. Consult it before making assumptions or implementing changes.
|
||||
|
||||
## Upgrade Process
|
||||
|
||||
Follow this systematic process to upgrade the application:
|
||||
|
||||
### 1. Assess Current State
|
||||
|
||||
Before making any changes:
|
||||
|
||||
- Check `composer.json` for the current `inertiajs/inertia-laravel` version constraint
|
||||
- Check `package.json` for the current `@inertiajs/*` adapter version
|
||||
- Run `{{ $assist->composerCommand('show inertiajs/inertia-laravel') }}` to confirm installed server version
|
||||
- Identify all Inertia pages in `{{ $assist->inertia()->pagesDirectory() }}`
|
||||
- Review `config/inertia.php` for current configuration
|
||||
- Review your Vite and SSR setup if the application server-renders Inertia pages
|
||||
|
||||
### 2. Create Safety Net
|
||||
|
||||
- Ensure you're working on a dedicated branch
|
||||
- Run the existing test suite to establish baseline
|
||||
- Note any components with complex JavaScript interactions
|
||||
|
||||
### 3. Analyze Codebase for Breaking Changes
|
||||
|
||||
Search the codebase for patterns affected by v3 changes:
|
||||
|
||||
**High Priority Searches:**
|
||||
- `router.on('invalid'` or `inertia:invalid` - Rename to `httpException`
|
||||
- `router.on('exception'` or `inertia:exception` - Rename to `networkError`
|
||||
- `router.cancel(` - Renamed to `router.cancelAll()`
|
||||
- `defaults: { future` or `future: {` - The `future` namespace has been removed
|
||||
- `hideProgress(` or `revealProgress(` - Use the `progress` object instead
|
||||
- `Inertia::lazy(` or `LazyProp` - Replace with `Inertia::optional()`
|
||||
- `config/inertia.php` - Configuration structure has changed
|
||||
|
||||
**Medium Priority Searches:**
|
||||
- `qs` imports - Install `qs` directly if the application uses it
|
||||
- `lodash-es` imports - Install `lodash-es` directly if the application uses it
|
||||
- `axios` imports or interceptors - Decide whether the app should keep Axios or rely on Inertia's built-in HTTP client
|
||||
- `Inertia\\Testing\\Concerns\\Has`, `Matching`, or `Debugging` - Deprecated traits removed in v3
|
||||
- `require(` in frontend code - Inertia packages are now ESM-only
|
||||
@if($usesReact)
|
||||
- `import { Deferred }` - React deferred partial reload behavior changed
|
||||
@endif
|
||||
@if($usesSvelte)
|
||||
- Non-runes Svelte components - Update to Svelte 5 runes syntax (`$props()`, `$state()`, `$effect()`, etc.)
|
||||
@endif
|
||||
|
||||
**Low Priority Searches:**
|
||||
- `vite build --ssr` or `inertia:start-ssr` in development scripts - Dev SSR flow changed when using `@inertiajs/vite`
|
||||
- `only`, `except`, `Deferred`, or `WhenVisible` with nested props - Dot notation support improved
|
||||
- `clearHistory` or `encryptHistory` - These page object keys are now omitted unless `true`
|
||||
|
||||
### 4. Apply Changes Systematically
|
||||
|
||||
For each category of changes:
|
||||
|
||||
1. **Search** for affected patterns using grep/search tools
|
||||
2. **Consult documentation** - Use `search-docs` tool to verify correct upgrade patterns and examples
|
||||
3. **List** all files that need modification
|
||||
4. **Apply** the fix consistently across all occurrences
|
||||
5. **Verify** each change doesn't break functionality
|
||||
|
||||
### 5. Update Dependencies
|
||||
|
||||
After code changes are complete:
|
||||
|
||||
- `{{ $assist->composerCommand('require inertiajs/inertia-laravel:^3.0') }}`
|
||||
@if($usesReact)
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/react@^3.0') }}`
|
||||
@endif
|
||||
@if($usesVue)
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/vue3@^3.0') }}`
|
||||
@endif
|
||||
@if($usesSvelte)
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/svelte@^3.0') }}`
|
||||
@endif
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/vite@^3.0') }}`
|
||||
- `{{ $assist->artisanCommand('vendor:publish --provider="Inertia\\\\ServiceProvider" --force') }}`
|
||||
- `{{ $assist->artisanCommand('view:clear') }}`
|
||||
|
||||
### 6. Test and Verify
|
||||
|
||||
- Run the full test suite
|
||||
- Manually test critical user flows
|
||||
- Check browser console for JavaScript errors
|
||||
- Verify error handling, deferred props, and form submission flows still behave correctly
|
||||
|
||||
## Execution Strategy
|
||||
|
||||
When upgrading, maximize efficiency by:
|
||||
|
||||
- **Batch similar changes** - Group all config updates, then all routing updates, etc.
|
||||
- **Use parallel agents** for independent file modifications
|
||||
- **Prioritize high-impact changes** that could cause immediate failures
|
||||
- **Test incrementally** - Verify after each category of changes
|
||||
|
||||
## Important Notes
|
||||
|
||||
- Inertia v3 requires PHP 8.2+, Laravel 11+, and Node 20+
|
||||
@if($usesReact)
|
||||
- React users must upgrade to React 19+
|
||||
@endif
|
||||
@if($usesSvelte)
|
||||
- Svelte users must upgrade to Svelte 5+ and update components to Svelte 5 runes syntax
|
||||
@endif
|
||||
- Axios removal usually does not require code changes
|
||||
- If the application imports `qs`, install it directly instead of rewriting query handling blindly
|
||||
- After upgrading, republish the config file and clear cached views because the `@inertia` Blade directive output changed
|
||||
|
||||
---
|
||||
|
||||
# Upgrading from v2 to v3
|
||||
|
||||
Inertia v3 introduces significant improvements including removal of legacy dependencies, streamlined configuration, and better developer experience. This guide covers all breaking changes and migration steps.
|
||||
|
||||
## Requirements
|
||||
|
||||
Before upgrading, ensure your environment meets these minimum requirements:
|
||||
|
||||
- PHP 8.2+
|
||||
- Laravel 11+
|
||||
- Node 20+
|
||||
@if($usesReact)
|
||||
- React 19+
|
||||
@endif
|
||||
@if($usesSvelte)
|
||||
- Svelte 5+ with Svelte 5 runes syntax (`$props()`, `$state()`, `$effect()`, etc.)
|
||||
@endif
|
||||
|
||||
## Installation
|
||||
|
||||
Update your server-side adapter by running `{{ $assist->composerCommand('require inertiajs/inertia-laravel:^3.0') }}`.
|
||||
|
||||
Update your client-side adapter:
|
||||
|
||||
@if($usesReact)
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/react@^3.0') }}`
|
||||
@endif
|
||||
@if($usesVue)
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/vue3@^3.0') }}`
|
||||
@endif
|
||||
@if($usesSvelte)
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/svelte@^3.0') }}`
|
||||
@endif
|
||||
|
||||
You may also install the optional Vite plugin, which simplifies page resolution and SSR configuration:
|
||||
|
||||
- `{{ $assist->nodePackageManagerCommand('install @inertiajs/vite@^3.0') }}`
|
||||
|
||||
After updating, republish the config and clear caches:
|
||||
|
||||
- `{{ $assist->artisanCommand('vendor:publish --provider="Inertia\\\\ServiceProvider" --force') }}`
|
||||
- `{{ $assist->artisanCommand('view:clear') }}`
|
||||
|
||||
## High-impact changes
|
||||
|
||||
These changes are most likely to affect your application and should be reviewed carefully.
|
||||
|
||||
### Axios removed
|
||||
|
||||
Inertia v3 no longer ships with or requires Axios. For most applications, this requires no changes. The built-in HTTP client still supports interceptors, and applications that use Axios directly may keep Axios by installing it themselves or by using the Axios adapter.
|
||||
|
||||
- `{{ $assist->nodePackageManagerCommand('install axios') }}`
|
||||
|
||||
### `qs` dependency removed
|
||||
|
||||
The `qs` package is no longer bundled with `@inertiajs/core`. Inertia still handles its own query strings internally, but you should install `qs` directly if your application imports it.
|
||||
|
||||
- `{{ $assist->nodePackageManagerCommand('install qs') }}`
|
||||
|
||||
### `lodash-es` dependency removed
|
||||
|
||||
The `lodash-es` package has been replaced with `es-toolkit` and is no longer included as a dependency of `@inertiajs/core`. You should install `lodash-es` directly if your application imports it.
|
||||
|
||||
- `{{ $assist->nodePackageManagerCommand('install lodash-es') }}`
|
||||
|
||||
### Event renames
|
||||
|
||||
Two global events have been renamed for clarity:
|
||||
|
||||
@boostsnippet('Global Event Renames', 'js')
|
||||
// Before (v2)
|
||||
router.on('invalid', (event) => {})
|
||||
router.on('exception', (event) => {})
|
||||
|
||||
// After (v3)
|
||||
router.on('httpException', (event) => {})
|
||||
router.on('networkError', (event) => {})
|
||||
@endboostsnippet
|
||||
|
||||
If you use document-level event listeners, update the event names accordingly (e.g. `document.addEventListener('inertia:httpException', ...)`).
|
||||
|
||||
You may also handle these events per-visit using the new `onHttpException` and `onNetworkError` callbacks:
|
||||
|
||||
@boostsnippet('Per-Visit Event Callbacks', 'js')
|
||||
router.post('/users', data, {
|
||||
onHttpException: (response) => {
|
||||
return false
|
||||
},
|
||||
onNetworkError: (error) => {},
|
||||
})
|
||||
@endboostsnippet
|
||||
|
||||
Returning `false` from `onHttpException` or calling `event.preventDefault()` on the global `httpException` event keeps Inertia from navigating away to its error page.
|
||||
|
||||
### `router.cancel()` renamed to `router.cancelAll()`
|
||||
|
||||
@boostsnippet('Cancel Rename', 'js')
|
||||
// Before (v2)
|
||||
router.cancel()
|
||||
|
||||
// After (v3)
|
||||
router.cancelAll()
|
||||
router.cancelAll({ async: false, prefetch: false })
|
||||
@endboostsnippet
|
||||
|
||||
### Future options removed
|
||||
|
||||
The `future` configuration namespace has been removed. The four v2 future options are now always enabled and can no longer be configured:
|
||||
|
||||
@boostsnippet('Future Options Removed', 'js')
|
||||
// Before (v2)
|
||||
createInertiaApp({
|
||||
defaults: {
|
||||
future: {
|
||||
preserveEqualProps: true,
|
||||
useDataInertiaHeadAttribute: true,
|
||||
useDialogForErrorModal: true,
|
||||
useScriptElementForInitialPage: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// After (v3)
|
||||
createInertiaApp({
|
||||
// ...
|
||||
})
|
||||
@endboostsnippet
|
||||
|
||||
Initial page data is now always passed through a `<script type="application/json">` element. The old `data-page` attribute approach is no longer supported.
|
||||
|
||||
### Progress exports removed
|
||||
|
||||
The named exports `hideProgress()` and `revealProgress()` have been removed. If you need programmatic control, use the adapter's exported `progress` object instead.
|
||||
|
||||
@if($usesReact)
|
||||
@boostsnippet('Progress Exports React', 'js')
|
||||
import { progress } from '@inertiajs/react'
|
||||
|
||||
progress.hide()
|
||||
progress.reveal()
|
||||
@endboostsnippet
|
||||
@endif
|
||||
@if($usesVue)
|
||||
@boostsnippet('Progress Exports Vue', 'js')
|
||||
import { progress } from '@inertiajs/vue3'
|
||||
|
||||
progress.hide()
|
||||
progress.reveal()
|
||||
@endboostsnippet
|
||||
@endif
|
||||
@if($usesSvelte)
|
||||
@boostsnippet('Progress Exports Svelte', 'js')
|
||||
import { progress } from '@inertiajs/svelte'
|
||||
|
||||
progress.hide()
|
||||
progress.reveal()
|
||||
@endboostsnippet
|
||||
@endif
|
||||
|
||||
### `LazyProp` removed
|
||||
|
||||
The deprecated `Inertia::lazy()` method and `LazyProp` class have been removed. Use `Inertia::optional()` instead:
|
||||
|
||||
@boostsnippet('LazyProp Migration', 'php')
|
||||
// Before (v2)
|
||||
return Inertia::render('Users/Index', [
|
||||
'users' => Inertia::lazy(fn () => User::all()),
|
||||
]);
|
||||
|
||||
// After (v3)
|
||||
return Inertia::render('Users/Index', [
|
||||
'users' => Inertia::optional(fn () => User::all()),
|
||||
]);
|
||||
@endboostsnippet
|
||||
|
||||
## Medium-impact changes
|
||||
|
||||
### Config restructuring
|
||||
|
||||
The `config/inertia.php` file structure has changed. After upgrading, republish it with `{{ $assist->artisanCommand('vendor:publish --provider="Inertia\\\\ServiceProvider" --force') }}` and then re-apply any customizations on top of the new structure.
|
||||
|
||||
@boostsnippet('Config Restructuring', 'php')
|
||||
// Before (v2) - config/inertia.php
|
||||
'testing' => [
|
||||
'ensure_pages_exist' => true,
|
||||
'page_paths' => [resource_path('js/Pages')],
|
||||
'page_extensions' => ['js', 'jsx', 'svelte', 'ts', 'tsx', 'vue'],
|
||||
],
|
||||
|
||||
// After (v3) - config/inertia.php
|
||||
'pages' => [
|
||||
'ensure_pages_exist' => false,
|
||||
'paths' => [resource_path('js/Pages')],
|
||||
'extensions' => ['js', 'jsx', 'svelte', 'ts', 'tsx', 'vue'],
|
||||
],
|
||||
|
||||
'testing' => [
|
||||
'ensure_pages_exist' => true,
|
||||
],
|
||||
@endboostsnippet
|
||||
|
||||
@if($usesReact)
|
||||
### `Deferred` component behavior (React)
|
||||
|
||||
The React `<Deferred>` component no longer resets to its fallback during partial reloads. Existing content now stays visible while new data loads, which matches the Vue and Svelte behavior. A `reloading` slot prop is available when you want to show loading state during those partial reloads.
|
||||
|
||||
@endif
|
||||
|
||||
### Form `processing` reset timing
|
||||
|
||||
The `useForm` helper now resets `processing` and `progress` inside `onFinish`, not immediately when a response arrives. If you depend on the exact timing of `form.processing`, re-test those flows after upgrading.
|
||||
|
||||
### Testing concerns removed
|
||||
|
||||
The deprecated `Inertia\Testing\Concerns\Has`, `Matching`, and `Debugging` traits have been removed. They were replaced long ago by `AssertableInertia`, so no action is required unless your application still references those traits directly.
|
||||
|
||||
## Other changes
|
||||
|
||||
### Blade components
|
||||
|
||||
Inertia now provides `<x-inertia::head>` and `<x-inertia::app>` Blade components as an alternative to the `@inertiaHead` and `@inertia` directives. The head component accepts fallback content via its slot that only renders when SSR is not active, solving the long-standing issue of duplicate `<title>` tags in SSR applications. The existing directives continue to work and require no changes.
|
||||
|
||||
### ES2022 build target
|
||||
|
||||
Inertia packages now target ES2022, up from ES2020 in v2. You may use the `@vitejs/plugin-legacy` Vite plugin if your application needs to support older browsers.
|
||||
|
||||
### Optional Vite plugin
|
||||
|
||||
The new `@inertiajs/vite` plugin can simplify component resolution and SSR configuration. If you adopt it, review the official examples before changing your `createInertiaApp()` bootstrap.
|
||||
|
||||
### SSR in development
|
||||
|
||||
When using `@inertiajs/vite`, SSR now works in development by simply running your normal Vite dev server. You no longer need `vite build --ssr` or `php artisan inertia:start-ssr` during development.
|
||||
|
||||
### Middleware priority
|
||||
|
||||
The Inertia middleware is now automatically registered at the correct priority, so no manual middleware-priority customization is required.
|
||||
|
||||
### Nested prop types
|
||||
|
||||
Nested `Inertia::optional()`, `Inertia::defer()`, and `Inertia::merge()` values now resolve correctly inside closures and nested arrays. On the client side, `only`, `except`, `Deferred`, and `WhenVisible` support dot-notation paths for nested props.
|
||||
|
||||
@boostsnippet('Nested Prop Types', 'php')
|
||||
return Inertia::render('Dashboard', [
|
||||
'auth' => fn () => [
|
||||
'user' => Auth::user(),
|
||||
'notifications' => Inertia::defer(fn () => Auth::user()->unreadNotifications),
|
||||
'invoices' => Inertia::optional(fn () => Auth::user()->invoices),
|
||||
],
|
||||
]);
|
||||
@endboostsnippet
|
||||
|
||||
### ESM-only
|
||||
|
||||
All Inertia packages are now ESM-only. Replace any CommonJS `require()` imports with `import` statements.
|
||||
|
||||
### Page object changes
|
||||
|
||||
The `clearHistory` and `encryptHistory` keys are now omitted from the page object unless they are `true`. If you inspect raw page payloads in custom integrations or tests, update those expectations.
|
||||
|
||||
## Next steps: New features in v3
|
||||
|
||||
After completing the upgrade, the following new features are available. Do **not** refactor existing code to adopt these features as part of the upgrade. Just complete the breaking changes above. These are listed as next steps so you can explore them separately.
|
||||
|
||||
- **Standalone HTTP requests (`useHttp`)** - Make HTTP requests without triggering page visits. Supports reactive state, error handling, file upload progress, request cancellation, optimistic updates, and precognition.
|
||||
- **Optimistic updates** - Chain `router.optimistic()` before a visit to apply changes instantly on the client. Props revert automatically on failure. Works with router visits, `<Form>`, `useForm`, and `useHttp`.
|
||||
- **Instant visits** - Swap to the target page component immediately via `<Link href="/dashboard" component="Dashboard">` while the server request fires in the background.
|
||||
- **Layout props (`useLayoutProps`)** - Persistent layouts can declare defaults that pages override via `setLayoutProps()`. Supports named layouts, nested layouts, and static props.
|
||||
- **Exception handling (`handleExceptionsUsing`)** - Full control over error page rendering with access to shared data via `withSharedData()`.
|
||||
- **Default layout** - Set a default layout in `createInertiaApp()` instead of on every page.
|
||||
- **Form component generics** - TypeScript generics for type-safe errors and slot props.
|
||||
- **Enum support** - Use PHP enums directly in `Inertia::render()` responses.
|
||||
- **`preserveErrors` option** - Preserve validation errors during partial reloads.
|
||||
- **Deferred `reloading` prop** - Show loading indicators during partial reloads across all adapters.
|
||||
|
||||
Consult the `search-docs` tool for implementation details when you're ready to adopt any of these features.
|
||||
|
||||
## Getting help
|
||||
|
||||
If you encounter issues during the upgrade:
|
||||
|
||||
- Check the [upgrade guide](https://inertiajs.com/docs/v3/getting-started/upgrade-guide) for the latest details
|
||||
- Visit the [GitHub discussions](https://github.com/inertiajs/inertia/discussions) for community support
|
||||
38
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLaravelv13/UpgradeLaravelV13.php
vendored
Normal file
38
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLaravelv13/UpgradeLaravelV13.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Prompts\UpgradeLaravelv13;
|
||||
|
||||
use Laravel\Boost\Concerns\RendersBladeGuidelines;
|
||||
use Laravel\Boost\Install\Herd;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
use Laravel\Roster\Enums\Packages;
|
||||
use Laravel\Roster\Roster;
|
||||
|
||||
class UpgradeLaravelV13 extends Prompt
|
||||
{
|
||||
use RendersBladeGuidelines;
|
||||
|
||||
protected string $name = 'upgrade-laravel-v13';
|
||||
|
||||
protected string $title = 'upgrade_laravel_v13';
|
||||
|
||||
protected string $description = 'Provides step-by-step guidance for upgrading from Laravel 12.x to 13.0.';
|
||||
|
||||
public function shouldRegister(Roster $roster): bool
|
||||
{
|
||||
return $roster->usesVersion(Packages::LARAVEL, '12.0.0', '>=')
|
||||
&& $roster->usesVersion(Packages::LARAVEL, '13.0.0', '<');
|
||||
}
|
||||
|
||||
public function handle(): Response
|
||||
{
|
||||
$content = $this->renderBladeFile(__DIR__.'/upgrade-laravel-v13.blade.php', [
|
||||
'usesHerd' => app(Herd::class)->isInstalled(),
|
||||
]);
|
||||
|
||||
return Response::text($content);
|
||||
}
|
||||
}
|
||||
462
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLaravelv13/upgrade-laravel-v13.blade.php
vendored
Normal file
462
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLaravelv13/upgrade-laravel-v13.blade.php
vendored
Normal file
@@ -0,0 +1,462 @@
|
||||
# Laravel 12 to 13 Upgrade Specialist
|
||||
|
||||
You are an expert Laravel upgrade specialist with deep knowledge of both Laravel 12.x and 13.0. Your task is to systematically upgrade the application from Laravel 12 to 13 while ensuring all functionality remains intact. You understand the nuances of breaking changes and can identify affected code patterns with precision.
|
||||
|
||||
## Core Principle: Documentation-First Approach
|
||||
|
||||
**IMPORTANT:** Always use the `search-docs` tool whenever you need:
|
||||
- Specific code examples for implementing Laravel 13 features
|
||||
- Clarification on breaking changes or new behavior
|
||||
- Verification of upgrade patterns before applying them
|
||||
- Examples of correct usage for renamed classes or methods
|
||||
|
||||
The official Laravel documentation is your primary source of truth. Consult it before making assumptions or implementing changes.
|
||||
|
||||
## Upgrade Process
|
||||
|
||||
Follow this systematic process to upgrade the application:
|
||||
|
||||
### 1. Assess Current State
|
||||
|
||||
Before making any changes:
|
||||
|
||||
- Check `composer.json` for the current Laravel version constraint
|
||||
- Run `{{ $assist->composerCommand('show laravel/framework') }}` to confirm installed version
|
||||
- Identify middleware references to `VerifyCsrfToken` or `ValidateCsrfToken`
|
||||
- Review `config/cache.php` for serialization settings
|
||||
- Review `config/session.php` for cookie name configuration
|
||||
|
||||
### 2. Create Safety Net
|
||||
|
||||
- Ensure you're working on a dedicated branch
|
||||
- Run the existing test suite to establish baseline
|
||||
- Note any custom cache store implementations or queue driver implementations
|
||||
|
||||
### 3. Analyze Codebase for Breaking Changes
|
||||
|
||||
Search the codebase for patterns affected by v13 changes:
|
||||
|
||||
**High Priority Searches:**
|
||||
- `VerifyCsrfToken` or `ValidateCsrfToken` — Must rename to `PreventRequestForgery`
|
||||
- `composer.json` — Dependency version constraints to update
|
||||
- `phpunit.xml` or `pest` config — Test framework version compatibility
|
||||
|
||||
**Medium Priority Searches:**
|
||||
- `config/cache.php` — Check for `serializable_classes` configuration
|
||||
- Code that stores PHP objects in cache — May need explicit class allow-lists
|
||||
- `upsert` calls with empty `uniqueBy` — Now throws `InvalidArgumentException`
|
||||
|
||||
**Low Priority Searches:**
|
||||
- `$event->exceptionOccurred` — Renamed to `$event->exception` in `JobAttempted`
|
||||
- `$event->connection` on `QueueBusy` — Renamed to `$connectionName`
|
||||
- `pagination::default` or `pagination::simple-default` — View names changed
|
||||
- `Container::call` with nullable class defaults — Behavior changed
|
||||
- Manager `extend` callbacks using `$this` — Binding changed
|
||||
- Custom `Str` factories in tests — Now reset between tests
|
||||
|
||||
### 4. Apply Changes Systematically
|
||||
|
||||
For each category of changes:
|
||||
|
||||
1. **Search** for affected patterns using grep/search tools
|
||||
2. **Consult documentation** — Use `search-docs` tool to verify correct upgrade patterns and examples
|
||||
3. **List** all files that need modification
|
||||
4. **Apply** the fix consistently across all occurrences
|
||||
5. **Verify** each change doesn't break functionality
|
||||
|
||||
### 5. Update Dependencies
|
||||
|
||||
After code changes are complete:
|
||||
|
||||
```bash
|
||||
{{ $assist->composerCommand('require laravel/framework:^13.0 --with-all-dependencies') }}
|
||||
```
|
||||
|
||||
### 6. Test and Verify
|
||||
|
||||
- Run the full test suite
|
||||
- Verify CSRF protection still works correctly
|
||||
- Check cache read/write operations
|
||||
- Test any queue listeners that reference event properties
|
||||
|
||||
## Execution Strategy
|
||||
|
||||
When upgrading, maximize efficiency by:
|
||||
|
||||
- **Batch similar changes** — Group all CSRF middleware renames, then all config updates, etc.
|
||||
- **Use parallel agents** for independent file modifications
|
||||
- **Prioritize high-impact changes** that could cause immediate failures
|
||||
- **Test incrementally** — Verify after each category of changes
|
||||
|
||||
|
||||
# Upgrading from Laravel 12.x to 13.0
|
||||
|
||||
> [!NOTE]
|
||||
> We attempt to document every possible breaking change. Since some of these breaking changes are in obscure parts of the framework only a portion of these changes may actually affect your application.
|
||||
|
||||
## Updating Dependencies
|
||||
|
||||
**Likelihood Of Impact: High**
|
||||
|
||||
Update the following dependencies in your application's `composer.json` file:
|
||||
|
||||
@boostsnippet('Dependency Updates', 'json')
|
||||
{
|
||||
"require": {
|
||||
"laravel/framework": "^13.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/tinker": "^3.0",
|
||||
"phpunit/phpunit": "^12.0",
|
||||
"pestphp/pest": "^4.0"
|
||||
}
|
||||
}
|
||||
@endboostsnippet
|
||||
|
||||
Run the update:
|
||||
|
||||
```bash
|
||||
{{ $assist->composerCommand('update') }}
|
||||
```
|
||||
|
||||
## Updating the Laravel Installer
|
||||
|
||||
If you use the Laravel installer CLI tool, update it for Laravel 13.x compatibility:
|
||||
|
||||
@if($usesHerd)
|
||||
```bash
|
||||
herd laravel:update
|
||||
```
|
||||
@else
|
||||
```bash
|
||||
{{ $assist->composerCommand('global update laravel/installer') }}
|
||||
```
|
||||
@endif
|
||||
|
||||
## Cache
|
||||
|
||||
### Cache Prefixes and Session Cookie Names
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
Laravel's default cache and Redis key prefixes now use hyphenated suffixes. In addition, the default session cookie name now uses `Str::snake(...)` for the application name.
|
||||
|
||||
In most applications, this change will not apply because application-level configuration files already define these values. This primarily affects applications that rely on framework-level fallback configuration when corresponding application config values are not present.
|
||||
|
||||
If your application relies on these generated defaults, cache keys and session cookie names may change after upgrading:
|
||||
|
||||
@boostsnippet('Cache Prefix Changes', 'php')
|
||||
// Laravel <= 12.x
|
||||
Str::slug((string) env('APP_NAME', 'laravel'), '_').'_cache_';
|
||||
Str::slug((string) env('APP_NAME', 'laravel'), '_').'_database_';
|
||||
Str::slug((string) env('APP_NAME', 'laravel'), '_').'_session';
|
||||
|
||||
// Laravel >= 13.x
|
||||
Str::slug((string) env('APP_NAME', 'laravel')).'-cache-';
|
||||
Str::slug((string) env('APP_NAME', 'laravel')).'-database-';
|
||||
Str::snake((string) env('APP_NAME', 'laravel')).'_session';
|
||||
@endboostsnippet
|
||||
|
||||
> [!IMPORTANT]
|
||||
> To retain previous behavior, explicitly configure `CACHE_PREFIX`, `REDIS_PREFIX`, and `SESSION_COOKIE` in your environment.
|
||||
|
||||
### `Store` and `Repository` Contracts: `touch`
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
The cache contracts now include a `touch` method for extending item TTLs. If you maintain custom cache store implementations, you should add this method:
|
||||
|
||||
@boostsnippet('Cache Store Touch', 'php')
|
||||
// Illuminate\Contracts\Cache\Store
|
||||
public function touch($key, $seconds);
|
||||
@endboostsnippet
|
||||
|
||||
### Cache `serializable_classes` Configuration
|
||||
|
||||
**Likelihood Of Impact: Medium**
|
||||
|
||||
The default application `cache` configuration now includes a `serializable_classes` option set to `false`. This hardens cache unserialization behavior to help prevent PHP deserialization gadget chain attacks if your application's `APP_KEY` is leaked. If your application intentionally stores PHP objects in cache, you should explicitly list the classes that may be unserialized:
|
||||
|
||||
@boostsnippet('Cache Serializable Classes', 'php')
|
||||
'serializable_classes' => [
|
||||
App\Data\CachedDashboardStats::class,
|
||||
App\Support\CachedPricingSnapshot::class,
|
||||
],
|
||||
@endboostsnippet
|
||||
|
||||
If your application previously relied on unserializing arbitrary cached objects, you will need to migrate that usage to explicit class allow-lists or to non-object cache payloads (such as arrays).
|
||||
|
||||
## Container
|
||||
|
||||
### `Container::call` and Nullable Class Defaults
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
`Container::call` now respects nullable class parameter defaults when no binding exists, matching constructor injection behavior introduced in Laravel 12:
|
||||
|
||||
@boostsnippet('Container Call Nullable', 'php')
|
||||
$container->call(function (?Carbon $date = null) {
|
||||
return $date;
|
||||
});
|
||||
|
||||
// Laravel <= 12.x: Carbon instance
|
||||
// Laravel >= 13.x: null
|
||||
@endboostsnippet
|
||||
|
||||
If your method-call injection logic depended on the previous behavior, you may need to update it.
|
||||
|
||||
## Contracts
|
||||
|
||||
### `Dispatcher` Contract: `dispatchAfterResponse`
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
The `Illuminate\Contracts\Bus\Dispatcher` contract now includes the `dispatchAfterResponse($command, $handler = null)` method.
|
||||
|
||||
If you maintain a custom dispatcher implementation, add this method to your class.
|
||||
|
||||
### `ResponseFactory` Contract: `eventStream`
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
The `Illuminate\Contracts\Routing\ResponseFactory` contract now includes an `eventStream` signature.
|
||||
|
||||
If you maintain a custom implementation of this contract, you should add this method.
|
||||
|
||||
### `MustVerifyEmail` Contract: `markEmailAsUnverified`
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
The `Illuminate\Contracts\Auth\MustVerifyEmail` contract now includes `markEmailAsUnverified()`.
|
||||
|
||||
If you provide a custom implementation of this contract, add this method to remain compatible.
|
||||
|
||||
## Database
|
||||
|
||||
### Database `upsert` With MySQL or MariaDB
|
||||
|
||||
**Likelihood Of Impact: Medium**
|
||||
|
||||
Laravel now validates that the caller provides a non-empty value for `uniqueBy`, and will throw an `InvalidArgumentException` instead of generating invalid SQL.
|
||||
|
||||
Although the MariaDB and MySQL database drivers ignore the `uniqueBy` value and always use the table's primary and unique indexes to detect existing records, the validation still applies. An `InvalidArgumentException` will be thrown if `uniqueBy` is empty.
|
||||
|
||||
### MySQL `DELETE` Queries With `JOIN`, `ORDER BY`, and `LIMIT`
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
Laravel now compiles full `DELETE ... JOIN` queries including `ORDER BY` and `LIMIT` for MySQL grammar.
|
||||
|
||||
In previous versions, `ORDER BY` / `LIMIT` clauses could be silently ignored on joined deletes. In Laravel 13, these clauses are included in the generated SQL. As a result, database engines that do not support this syntax (such as standard MySQL / MariaDB variants) may now throw a `QueryException` instead of executing an unbounded delete.
|
||||
|
||||
## Eloquent
|
||||
|
||||
### Model Booting and Nested Instantiation
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
Creating a new model instance while that model is still booting is now disallowed and throws a `LogicException`.
|
||||
|
||||
This affects code that instantiates models from inside model `boot` methods or trait `boot*` methods:
|
||||
|
||||
@boostsnippet('Model Booting', 'php')
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
// No longer allowed during booting...
|
||||
(new static())->getTable();
|
||||
}
|
||||
@endboostsnippet
|
||||
|
||||
Move this logic outside the boot cycle to avoid nested booting.
|
||||
|
||||
### Polymorphic Pivot Table Name Generation
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
When table names are inferred for polymorphic pivot models using custom pivot model classes, Laravel now generates pluralized names.
|
||||
|
||||
If your application depended on the previous singular inferred names for morph pivot tables and used custom pivot classes, you should explicitly define the table name on your pivot model.
|
||||
|
||||
### Collection Model Serialization Restores Eager-Loaded Relations
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
When Eloquent model collections are serialized and restored (such as in queued jobs), eager-loaded relations are now restored for the collection's models.
|
||||
|
||||
If your code depended on relations not being present after deserialization, you may need to adjust that logic.
|
||||
|
||||
## HTTP Client
|
||||
|
||||
### HTTP Client `Response::throw` and `throwIf` Signatures
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
The HTTP client response methods now declare their callback parameters in the method signatures:
|
||||
|
||||
@boostsnippet('HTTP Client Throw Signatures', 'php')
|
||||
public function throw($callback = null);
|
||||
public function throwIf($condition, $callback = null);
|
||||
@endboostsnippet
|
||||
|
||||
If you override these methods in custom response classes, ensure your method signatures are compatible.
|
||||
|
||||
## Notifications
|
||||
|
||||
### Default Password Reset Subject
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
Laravel's default password reset mail subject has changed:
|
||||
|
||||
@boostsnippet('Password Reset Subject', 'text')
|
||||
// Laravel <= 12.x
|
||||
Reset Password Notification
|
||||
|
||||
// Laravel >= 13.x
|
||||
Reset your password
|
||||
@endboostsnippet
|
||||
|
||||
If your tests, assertions, or translation overrides depend on the previous default string, update them accordingly.
|
||||
|
||||
### Queued Notifications and Missing Models
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
Queued notifications now respect the `#[DeleteWhenMissingModels]` attribute and `$deleteWhenMissingModels` property defined on the notification class.
|
||||
|
||||
In previous versions, missing models could still cause queued notification jobs to fail in cases where you expected them to be deleted.
|
||||
|
||||
## Queue
|
||||
|
||||
### `JobAttempted` Event Exception Payload
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
The `Illuminate\Queue\Events\JobAttempted` event now exposes the exception object (or `null`) via `$exception`, replacing the previous boolean `$exceptionOccurred` property:
|
||||
|
||||
@boostsnippet('JobAttempted Event', 'php')
|
||||
// Laravel <= 12.x
|
||||
$event->exceptionOccurred;
|
||||
|
||||
// Laravel >= 13.x
|
||||
$event->exception;
|
||||
@endboostsnippet
|
||||
|
||||
If you listen for this event, update your listener code accordingly.
|
||||
|
||||
### `QueueBusy` Event Property Rename
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
The `Illuminate\Queue\Events\QueueBusy` event property `$connection` has been renamed to `$connectionName` for consistency with other queue events.
|
||||
|
||||
If your listeners reference `$connection`, update them to `$connectionName`.
|
||||
|
||||
### `Queue` Contract Method Additions
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
The `Illuminate\Contracts\Queue\Queue` contract now includes queue size inspection methods that were previously only declared in docblocks.
|
||||
|
||||
If you maintain custom queue driver implementations of this contract, add implementations for:
|
||||
|
||||
- `pendingSize`
|
||||
- `delayedSize`
|
||||
- `reservedSize`
|
||||
- `creationTimeOfOldestPendingJob`
|
||||
|
||||
## Routing
|
||||
|
||||
### Domain Route Registration Precedence
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
Routes with an explicit domain are now prioritized before non-domain routes in route matching.
|
||||
|
||||
This allows catch-all subdomain routes to behave consistently even when non-domain routes are registered earlier. If your application relied on previous registration precedence between domain and non-domain routes, review route matching behavior.
|
||||
|
||||
## Scheduling
|
||||
|
||||
### `withScheduling` Registration Timing
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
Schedules registered via `ApplicationBuilder::withScheduling()` are now deferred until `Schedule` is resolved.
|
||||
|
||||
If your application relied on immediate schedule registration timing during bootstrap, you may need to adjust that logic.
|
||||
|
||||
## Security
|
||||
|
||||
### Request Forgery Protection
|
||||
|
||||
**Likelihood Of Impact: High**
|
||||
|
||||
Laravel's CSRF middleware has been renamed from `VerifyCsrfToken` to `PreventRequestForgery`, and now includes request-origin verification using the `Sec-Fetch-Site` header.
|
||||
|
||||
`VerifyCsrfToken` and `ValidateCsrfToken` remain as deprecated aliases, but direct references should be updated to `PreventRequestForgery`, especially when excluding middleware in tests or route definitions:
|
||||
|
||||
@boostsnippet('CSRF Middleware Rename', 'php')
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
|
||||
// Laravel <= 12.x
|
||||
->withoutMiddleware([VerifyCsrfToken::class]);
|
||||
|
||||
// Laravel >= 13.x
|
||||
->withoutMiddleware([PreventRequestForgery::class]);
|
||||
@endboostsnippet
|
||||
|
||||
The middleware configuration API now also provides `preventRequestForgery(...)`.
|
||||
|
||||
## Support
|
||||
|
||||
### Manager `extend` Callback Binding
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
Custom driver closures registered via manager `extend` methods are now bound to the manager instance.
|
||||
|
||||
If you previously relied on another bound object (such as a service provider instance) as `$this` inside these callbacks, you should move those values into closure captures using `use (...)`.
|
||||
|
||||
### `Str` Factories Reset Between Tests
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
Laravel now resets custom `Str` factories during test teardown.
|
||||
|
||||
If your tests depended on custom UUID / ULID / random string factories persisting between test methods, you should set them in each relevant test or setup hook.
|
||||
|
||||
### `Js::from` Uses Unescaped Unicode By Default
|
||||
|
||||
**Likelihood Of Impact: Very Low**
|
||||
|
||||
`Illuminate\Support\Js::from` now uses `JSON_UNESCAPED_UNICODE` by default.
|
||||
|
||||
If your tests or frontend output comparisons depended on escaped Unicode sequences (for example `\u00e8`), update your expectations.
|
||||
|
||||
## Views
|
||||
|
||||
### Pagination Bootstrap View Names
|
||||
|
||||
**Likelihood Of Impact: Low**
|
||||
|
||||
The internal pagination view names for Bootstrap 3 defaults are now explicit:
|
||||
|
||||
@boostsnippet('Pagination Views', 'text')
|
||||
// Laravel <= 12.x
|
||||
pagination::default
|
||||
pagination::simple-default
|
||||
|
||||
// Laravel >= 13.x
|
||||
pagination::bootstrap-3
|
||||
pagination::simple-bootstrap-3
|
||||
@endboostsnippet
|
||||
|
||||
## Getting help
|
||||
|
||||
If you encounter issues during the upgrade:
|
||||
|
||||
- Check the [upgrade guide](https://laravel.com/docs/13.x/upgrade) for the latest details
|
||||
- Review the [GitHub comparison](https://github.com/laravel/laravel/compare/12.x...13.x) for skeleton changes
|
||||
34
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLivewirev4/UpgradeLivewireV4.php
vendored
Normal file
34
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLivewirev4/UpgradeLivewireV4.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Prompts\UpgradeLivewirev4;
|
||||
|
||||
use Laravel\Boost\Concerns\RendersBladeGuidelines;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
use Laravel\Roster\Enums\Packages;
|
||||
use Laravel\Roster\Roster;
|
||||
|
||||
class UpgradeLivewireV4 extends Prompt
|
||||
{
|
||||
use RendersBladeGuidelines;
|
||||
|
||||
protected string $name = 'upgrade-livewire-v4';
|
||||
|
||||
protected string $title = 'upgrade_livewire_v4';
|
||||
|
||||
protected string $description = 'Provides step-by-step guidance for upgrading from Livewire v3 to v4.';
|
||||
|
||||
public function shouldRegister(Roster $roster): bool
|
||||
{
|
||||
return $roster->uses(Packages::LIVEWIRE);
|
||||
}
|
||||
|
||||
public function handle(): Response
|
||||
{
|
||||
$content = $this->renderBladeFile(__DIR__.'/upgrade-livewire-v4.blade.php');
|
||||
|
||||
return Response::text($content);
|
||||
}
|
||||
}
|
||||
825
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLivewirev4/upgrade-livewire-v4.blade.php
vendored
Normal file
825
vendor/laravel/boost/src/Mcp/Prompts/UpgradeLivewirev4/upgrade-livewire-v4.blade.php
vendored
Normal file
@@ -0,0 +1,825 @@
|
||||
# Livewire v3 to v4 Upgrade Specialist
|
||||
|
||||
You are an expert Livewire upgrade specialist with deep knowledge of both Livewire v3 and v4. Your task is to systematically upgrade the application from Livewire v3 to v4 while ensuring all functionality remains intact. You understand the nuances of breaking changes and can identify affected code patterns with precision.
|
||||
|
||||
## Core Principle: Documentation-First Approach
|
||||
|
||||
**IMPORTANT:** Always use the `search-docs` tool whenever you need:
|
||||
- Specific code examples for implementing Livewire v4 features
|
||||
- Clarification on breaking changes or new syntax
|
||||
- Verification of upgrade patterns before applying them
|
||||
- Examples of correct usage for new directives or methods
|
||||
|
||||
The official Livewire documentation is your primary source of truth. Consult it before making assumptions or implementing changes.
|
||||
|
||||
## Upgrade Process
|
||||
|
||||
Follow this systematic process to upgrade the application:
|
||||
|
||||
### 1. Assess Current State
|
||||
|
||||
Before making any changes:
|
||||
|
||||
- Check `composer.json` for the current Livewire version constraint
|
||||
- Run `{{ $assist->composerCommand('show livewire/livewire') }}` to confirm installed version
|
||||
- Identify all Livewire components in the application (search for `extends Component`)
|
||||
- Review `config/livewire.php` for current configuration
|
||||
|
||||
### 2. Create Safety Net
|
||||
|
||||
- Ensure you're working on a dedicated branch
|
||||
- Run the existing test suite to establish baseline
|
||||
- Note any components with complex JavaScript interactions
|
||||
|
||||
### 3. Analyze Codebase for Breaking Changes
|
||||
|
||||
Search the codebase for patterns affected by v4 changes:
|
||||
|
||||
**High Priority Searches:**
|
||||
- `config/livewire.php` - Configuration key renames needed
|
||||
- `Route::get` with Livewire components - May need `Route::livewire()`
|
||||
- `wire:model` on container elements (divs, modals) - Check for bubbling behavior
|
||||
- `wire:scroll` - Needs rename to `wire:navigate:scroll`
|
||||
- `<livewire:` tags - Must be properly closed (self-closing or with closing tag)
|
||||
|
||||
**Medium Priority Searches:**
|
||||
- `wire:transition` with modifiers (`.opacity`, `.scale`, `.duration`) - Modifiers removed
|
||||
- `$this->stream(` - Parameter order changed
|
||||
- Array property replacements from JavaScript - Hook behavior changed
|
||||
|
||||
**Low Priority Searches:**
|
||||
- `$wire.$js(` or `$js(` - Deprecated syntax
|
||||
- `Livewire.hook('commit'` or `Livewire.hook('request'` - Deprecated hooks
|
||||
|
||||
### 4. Apply Changes Systematically
|
||||
|
||||
For each category of changes:
|
||||
|
||||
1. **Search** for affected patterns using grep/search tools
|
||||
2. **Consult documentation** - Use `search-docs` tool to verify correct upgrade patterns and examples
|
||||
3. **List** all files that need modification
|
||||
4. **Apply** the fix consistently across all occurrences
|
||||
5. **Verify** each change doesn't break functionality
|
||||
|
||||
### 5. Update Dependencies
|
||||
|
||||
After code changes are complete:
|
||||
|
||||
```bash
|
||||
{{ $assist->composerCommand('require livewire/livewire:^4.0') }}
|
||||
{{ $assist->artisanCommand('optimize:clear') }}
|
||||
```
|
||||
|
||||
### 6. Test and Verify
|
||||
|
||||
- Run the full test suite
|
||||
- Manually test critical user flows
|
||||
- Check browser console for JavaScript errors
|
||||
- Verify all components render correctly
|
||||
|
||||
## Execution Strategy
|
||||
|
||||
When upgrading, maximize efficiency by:
|
||||
|
||||
- **Batch similar changes** - Group all config updates, then all routing updates, etc.
|
||||
- **Use parallel agents** for independent file modifications
|
||||
- **Prioritize high-impact changes** that could cause immediate failures
|
||||
- **Test incrementally** - Verify after each category of changes
|
||||
|
||||
## Important Notes
|
||||
|
||||
- Most applications can upgrade with minimal changes
|
||||
- The old syntax for deprecated features still works but should be migrated
|
||||
|
||||
---
|
||||
|
||||
# Upgrading from v3 to v4
|
||||
|
||||
Livewire v4 introduces several improvements and optimizations while maintaining backward compatibility wherever possible. This guide will help you upgrade from Livewire v3 to v4.
|
||||
|
||||
> [!tip] Smooth upgrade path
|
||||
> Most applications can upgrade to v4 with minimal changes. The breaking changes are primarily configuration updates and method signature changes that only affect advanced usage.
|
||||
|
||||
## Installation
|
||||
|
||||
Update your `composer.json` to require Livewire v4:
|
||||
|
||||
@boostsnippet('Installation', 'bash')
|
||||
composer require livewire/livewire:^4.0
|
||||
@endboostsnippet
|
||||
|
||||
After updating, clear your application's cache:
|
||||
|
||||
@boostsnippet('Clear Cache', 'bash')
|
||||
php artisan optimize:clear
|
||||
@endboostsnippet
|
||||
|
||||
> [!info] View all changes on GitHub
|
||||
> For a complete overview of all code changes between v3 and v4, you can review the full diff on GitHub: [Compare 3.x to main →](https://github.com/livewire/livewire/compare/3.x...main)
|
||||
|
||||
## High-impact changes
|
||||
|
||||
These changes are most likely to affect your application and should be reviewed carefully.
|
||||
|
||||
### Config file updates
|
||||
|
||||
Several configuration keys have been renamed, reorganized, or have new defaults. Update your `config/livewire.php` file:
|
||||
|
||||
> [!tip] View the full config file
|
||||
> For reference, you can view the complete v4 config file on GitHub: [livewire.php →](https://github.com/livewire/livewire/blob/main/config/livewire.php)
|
||||
|
||||
#### Renamed configuration keys
|
||||
|
||||
**Layout configuration:**
|
||||
|
||||
@boostsnippet('Layout Configuration', 'php')
|
||||
// Before (v3)
|
||||
'layout' => 'components.layouts.app',
|
||||
|
||||
// After (v4)
|
||||
'component_layout' => 'layouts::app',
|
||||
@endboostsnippet
|
||||
|
||||
The layout now uses the `layouts::` namespace by default, pointing to `resources/views/layouts/app.blade.php`.
|
||||
|
||||
**Placeholder configuration:**
|
||||
|
||||
@boostsnippet('Placeholder Configuration', 'php')
|
||||
// Before (v3)
|
||||
'lazy_placeholder' => 'livewire.placeholder',
|
||||
|
||||
// After (v4)
|
||||
'component_placeholder' => 'livewire.placeholder',
|
||||
@endboostsnippet
|
||||
|
||||
#### Changed defaults
|
||||
|
||||
**Smart wire:key behavior:**
|
||||
|
||||
@boostsnippet('Smart Wire Key', 'php')
|
||||
// Now defaults to true (was false in v3)
|
||||
'smart_wire_keys' => true,
|
||||
@endboostsnippet
|
||||
|
||||
This helps prevent wire:key issues on deeply nested components. Note: You still need to add `wire:key` manually in loops—this setting doesn't eliminate that requirement.
|
||||
|
||||
[Learn more about wire:key →](/docs/4.x/nesting#rendering-children-in-a-loop)
|
||||
|
||||
#### New configuration options
|
||||
|
||||
**Component locations:**
|
||||
|
||||
@boostsnippet('Component Locations', 'php')
|
||||
'component_locations' => [
|
||||
resource_path('views/components'),
|
||||
resource_path('views/livewire'),
|
||||
],
|
||||
@endboostsnippet
|
||||
|
||||
Defines where Livewire looks for single-file and multi-file (view-based) components.
|
||||
|
||||
**Component namespaces:**
|
||||
|
||||
@boostsnippet('Component Namespaces', 'php')
|
||||
'component_namespaces' => [
|
||||
'layouts' => resource_path('views/layouts'),
|
||||
'pages' => resource_path('views/pages'),
|
||||
],
|
||||
@endboostsnippet
|
||||
|
||||
Creates custom namespaces for organizing view-based components (e.g., `<livewire:pages::dashboard />`).
|
||||
|
||||
**Make command defaults:**
|
||||
|
||||
@boostsnippet('Make Command Defaults', 'php')
|
||||
'make_command' => [
|
||||
'type' => 'sfc', // Options: 'sfc', 'mfc', or 'class'
|
||||
'emoji' => true, // Whether to use ⚡ emoji prefix
|
||||
],
|
||||
@endboostsnippet
|
||||
|
||||
Configure default component format and emoji usage. Set `type` to `'class'` to match v3 behavior.
|
||||
|
||||
**CSP-safe mode:**
|
||||
|
||||
@boostsnippet('CSP Safe Mode', 'php')
|
||||
'csp_safe' => false,
|
||||
@endboostsnippet
|
||||
|
||||
Enable Content Security Policy mode to avoid `unsafe-eval` violations. When enabled, Livewire uses the [Alpine CSP build](https://alpinejs.dev/advanced/csp). Note: This mode restricts complex JavaScript expressions in directives like `wire:click="addToCart($event.detail.productId)"` or global references like `window.location`.
|
||||
|
||||
### Routing changes
|
||||
|
||||
For full-page components, the recommended routing approach has changed:
|
||||
|
||||
@boostsnippet('Routing Changes', 'php')
|
||||
// Before (v3) - still works but not recommended
|
||||
Route::get('/dashboard', Dashboard::class);
|
||||
|
||||
// After (v4) - recommended for all component types
|
||||
Route::livewire('/dashboard', Dashboard::class);
|
||||
|
||||
// For view-based components, you can use the component name
|
||||
Route::livewire('/dashboard', 'pages::dashboard');
|
||||
@endboostsnippet
|
||||
|
||||
Using `Route::livewire()` is now the preferred method and is required for single-file and multi-file components to work correctly as full-page components.
|
||||
|
||||
[Learn more about routing →](/docs/4.x/components#page-components)
|
||||
|
||||
### `wire:model` now ignores child events by default
|
||||
|
||||
In v3, `wire:model` would respond to input/change events that bubbled up from child elements. This caused unexpected behavior when using `wire:model` on container elements (like modals or accordions) that contained form inputs—clearing an input inside would bubble up and potentially close the modal.
|
||||
|
||||
In v4, `wire:model` now only listens for events originating directly on the element itself (equivalent to the `.self` modifier behavior).
|
||||
|
||||
If you have code that relies on capturing events from child elements, add the `.deep` modifier:
|
||||
|
||||
@boostsnippet('Wire Model Deep', 'blade')
|
||||
<!-- Before (v3) - listened to child events by default -->
|
||||
<div wire:model="value">
|
||||
<input type="text">
|
||||
</div>
|
||||
|
||||
<!-- After (v4) - add .deep to restore old behavior -->
|
||||
<div wire:model.deep="value">
|
||||
<input type="text">
|
||||
</div>
|
||||
@endboostsnippet
|
||||
|
||||
> [!tip] Most apps won't need changes
|
||||
> This change primarily affects non-standard uses of `wire:model` on container elements. Standard form input bindings (inputs, selects, textareas) are unaffected.
|
||||
|
||||
### Use `wire:navigate:scroll`
|
||||
|
||||
When using `wire:scroll` to preserve scroll in a scrollable container across `wire:navigate` requests in v3, you will need to instead use `wire:navigate:scroll` in v4:
|
||||
|
||||
@boostsnippet('Wire Navigate Scroll', 'blade')
|
||||
@@persist('sidebar')
|
||||
<div class="overflow-y-scroll" wire:scroll> <!-- [tl! remove] -->
|
||||
<div class="overflow-y-scroll" wire:navigate:scroll> <!-- [tl! add] -->
|
||||
<!-- ... -->
|
||||
</div>
|
||||
@@endpersist
|
||||
@endboostsnippet
|
||||
|
||||
### Component tags must be closed
|
||||
|
||||
In v3, Livewire component tags would render even without being properly closed. In v4, with the addition of slot support, component tags must be properly closed—otherwise Livewire interprets subsequent content as slot content and the component won't render:
|
||||
|
||||
@boostsnippet('Component Tags Closed', 'blade')
|
||||
<!-- Before (v3) - unclosed tag -->
|
||||
<livewire:component-name>
|
||||
|
||||
<!-- After (v4) - Self-closing tag -->
|
||||
<livewire:component-name />
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about rendering components →](/docs/4.x/components#rendering-components)
|
||||
|
||||
[Learn more about slots →](/docs/4.x/nesting#slots)
|
||||
|
||||
## Medium-impact changes
|
||||
|
||||
These changes may affect certain parts of your application depending on which features you use.
|
||||
|
||||
### `wire:transition` now uses View Transitions API
|
||||
|
||||
In v3, `wire:transition` was a wrapper around Alpine's `x-transition` directive, supporting modifiers like `.opacity`, `.scale`, `.duration.200ms`, and `.origin.top`.
|
||||
|
||||
In v4, `wire:transition` uses the browser's native [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) instead. Basic usage still works—elements will fade in and out smoothly—but all modifiers have been removed.
|
||||
|
||||
@boostsnippet('Wire Transition', 'blade')
|
||||
<!-- This still works in v4 -->
|
||||
<div wire:transition>...</div>
|
||||
|
||||
<!-- These modifiers are no longer supported -->
|
||||
<div wire:transition.opacity>...</div> <!-- [tl! remove] -->
|
||||
<div wire:transition.scale.origin.top>...</div> <!-- [tl! remove] -->
|
||||
<div wire:transition.duration.500ms>...</div> <!-- [tl! remove] -->
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about wire:transition →](/docs/4.x/wire-transition)
|
||||
|
||||
### Performance improvements
|
||||
|
||||
Livewire v4 includes significant performance improvements to the request handling system:
|
||||
|
||||
- **Non-blocking polling**: `wire:poll` no longer blocks other requests or is blocked by them
|
||||
- **Parallel live updates**: `wire:model.live` requests now run in parallel, allowing faster typing and quicker results
|
||||
|
||||
These improvements happen automatically—no changes needed to your code.
|
||||
|
||||
### Update hooks consolidate array/object changes
|
||||
|
||||
When replacing an entire array or object from the frontend (e.g., `$wire.items = ['new', 'values']`), Livewire now sends a single consolidated update instead of granular updates for each index.
|
||||
|
||||
**Before:** Setting `$wire.items = ['a', 'b']` on an array of 4 items would fire `updatingItems`/`updatedItems` hooks multiple times—once for each index change plus `__rm__` removals.
|
||||
|
||||
**After:** The same operation fires the hooks once with the full new array value, matching v2 behavior.
|
||||
|
||||
If your code relies on individual index hooks firing when replacing entire arrays, you may need to adjust. Single-item changes (like `wire:model="items.0"`) still fire granular hooks as expected.
|
||||
|
||||
### Method signature changes
|
||||
|
||||
If you're extending Livewire's core functionality or using these methods directly, note these signature changes:
|
||||
|
||||
**Streaming:**
|
||||
|
||||
The `stream()` method parameter order has changed:
|
||||
|
||||
@boostsnippet('Stream Method Signature', 'php')
|
||||
// Before (v3)
|
||||
$this->stream(to: '#container', content: 'Hello', replace: true);
|
||||
|
||||
// After (v4)
|
||||
$this->stream(content: 'Hello', replace: true, el: '#container');
|
||||
@endboostsnippet
|
||||
|
||||
If you're using named parameters (as shown above), note that `to:` has been renamed to `el:`. If you're using positional parameters, you'll need to update to the following:
|
||||
|
||||
@boostsnippet('Stream Positional Parameters', 'php')
|
||||
// Before (v3) - positional parameters
|
||||
$this->stream('#container', 'Hello');
|
||||
|
||||
// After (v4) - positional/named parameters
|
||||
$this->stream('Hello', el: '#container');
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about streaming →](/docs/4.x/wire-stream)
|
||||
|
||||
**Component mounting (internal):**
|
||||
|
||||
If you're extending `LivewireManager` or calling the `mount()` method directly:
|
||||
|
||||
@boostsnippet('Mount Method Signature', 'php')
|
||||
// Before (v3)
|
||||
public function mount($name, $params = [], $key = null)
|
||||
|
||||
// After (v4)
|
||||
public function mount($name, $params = [], $key = null, $slots = [])
|
||||
@endboostsnippet
|
||||
|
||||
This change adds support for passing slots when mounting components and generally won't affect most applications.
|
||||
|
||||
## Low-impact changes
|
||||
|
||||
These changes only affect applications using advanced features or customization.
|
||||
|
||||
### JavaScript deprecations
|
||||
|
||||
#### Deprecated: `$wire.$js()` method
|
||||
|
||||
The `$wire.$js()` method for defining JavaScript actions has been deprecated:
|
||||
|
||||
@boostsnippet('Wire JS Deprecation', 'js')
|
||||
// Deprecated (v3)
|
||||
$wire.$js('bookmark', () => {
|
||||
// Toggle bookmark...
|
||||
})
|
||||
|
||||
// New (v4)
|
||||
$wire.$js.bookmark = () => {
|
||||
// Toggle bookmark...
|
||||
}
|
||||
@endboostsnippet
|
||||
|
||||
The new syntax is cleaner and more intuitive.
|
||||
|
||||
#### Deprecated: `$js` without prefix
|
||||
|
||||
The use of `$js` in scripts without `$wire.$js` or `this.$js` prefix has been deprecated:
|
||||
|
||||
@boostsnippet('JS Without Prefix Deprecation', 'js')
|
||||
// Deprecated (v3)
|
||||
$js('bookmark', () => {
|
||||
// Toggle bookmark...
|
||||
})
|
||||
|
||||
// New (v4)
|
||||
$wire.$js.bookmark = () => {
|
||||
// Toggle bookmark...
|
||||
}
|
||||
// Or
|
||||
this.$js.bookmark = () => {
|
||||
// Toggle bookmark...
|
||||
}
|
||||
@endboostsnippet
|
||||
|
||||
> [!tip] Old syntax still works
|
||||
> Both `$wire.$js('bookmark', ...)` and `$js('bookmark', ...)` will continue to work in v4 for backward compatibility, but you should migrate to the new syntax when convenient.
|
||||
|
||||
#### Deprecated: `commit` and `request` hooks
|
||||
|
||||
The `commit` and `request` hooks have been deprecated in favor of a new interceptor system that provides more granular control and better performance.
|
||||
|
||||
> [!tip] Old hooks still work
|
||||
> The deprecated hooks will continue to work in v4 for backward compatibility, but you should migrate to the new system when convenient.
|
||||
|
||||
#### Migrating from `commit` hook
|
||||
|
||||
The old `commit` hook:
|
||||
|
||||
@boostsnippet('Old Commit Hook', 'js')
|
||||
// OLD - Deprecated
|
||||
Livewire.hook('commit', ({ component, commit, respond, succeed, fail }) => {
|
||||
respond(() => {
|
||||
// Runs after response received but before processing
|
||||
})
|
||||
|
||||
succeed(({ snapshot, effects }) => {
|
||||
// Runs after successful response
|
||||
})
|
||||
|
||||
fail(() => {
|
||||
// Runs if request failed
|
||||
})
|
||||
})
|
||||
@endboostsnippet
|
||||
|
||||
Should be replaced with the new `interceptMessage`:
|
||||
|
||||
@boostsnippet('New Intercept Message', 'js')
|
||||
// NEW - Recommended
|
||||
Livewire.interceptMessage(({ component, message, onFinish, onSuccess, onError, onFailure }) => {
|
||||
onFinish(() => {
|
||||
// Equivalent to respond()
|
||||
})
|
||||
|
||||
onSuccess(({ payload }) => {
|
||||
// Equivalent to succeed()
|
||||
// Access snapshot via payload.snapshot
|
||||
// Access effects via payload.effects
|
||||
})
|
||||
|
||||
onError(() => {
|
||||
// Equivalent to fail() for server errors
|
||||
})
|
||||
|
||||
onFailure(() => {
|
||||
// Equivalent to fail() for network errors
|
||||
})
|
||||
})
|
||||
@endboostsnippet
|
||||
|
||||
#### Migrating from `request` hook
|
||||
|
||||
The old `request` hook:
|
||||
|
||||
@boostsnippet('Old Request Hook', 'js')
|
||||
// OLD - Deprecated
|
||||
Livewire.hook('request', ({ url, options, payload, respond, succeed, fail }) => {
|
||||
respond(({ status, response }) => {
|
||||
// Runs when response received
|
||||
})
|
||||
|
||||
succeed(({ status, json }) => {
|
||||
// Runs on successful response
|
||||
})
|
||||
|
||||
fail(({ status, content, preventDefault }) => {
|
||||
// Runs on failed response
|
||||
})
|
||||
})
|
||||
@endboostsnippet
|
||||
|
||||
Should be replaced with the new `interceptRequest`:
|
||||
|
||||
@boostsnippet('New Intercept Request', 'js')
|
||||
// NEW - Recommended
|
||||
Livewire.interceptRequest(({ request, onResponse, onSuccess, onError, onFailure }) => {
|
||||
// Access url via request.uri
|
||||
// Access options via request.options
|
||||
// Access payload via request.payload
|
||||
|
||||
onResponse(({ response }) => {
|
||||
// Equivalent to respond()
|
||||
// Access status via response.status
|
||||
})
|
||||
|
||||
onSuccess(({ response, responseJson }) => {
|
||||
// Equivalent to succeed()
|
||||
// Access status via response.status
|
||||
// Access json via responseJson
|
||||
})
|
||||
|
||||
onError(({ response, responseBody, preventDefault }) => {
|
||||
// Equivalent to fail() for server errors
|
||||
// Access status via response.status
|
||||
// Access content via responseBody
|
||||
})
|
||||
|
||||
onFailure(({ error }) => {
|
||||
// Equivalent to fail() for network errors
|
||||
})
|
||||
})
|
||||
@endboostsnippet
|
||||
|
||||
#### Key differences
|
||||
|
||||
1. **More granular error handling**: The new system separates network failures (`onFailure`) from server errors (`onError`)
|
||||
2. **Better lifecycle hooks**: Message interceptors provide additional hooks like `onSync`, `onMorph`, and `onRender`
|
||||
3. **Cancellation support**: Both messages and requests can be cancelled/aborted
|
||||
4. **Component scoping**: Message interceptors can be scoped to specific components using `$wire.intercept(...)`
|
||||
|
||||
For complete documentation on the new interceptor system, see the [JavaScript Interceptors documentation](/docs/4.x/javascript#interceptors).
|
||||
|
||||
## Upgrading Volt
|
||||
|
||||
Livewire v4 now supports single-file components, which use the same syntax as Volt class-based components. This means you can migrate from Volt to Livewire's built-in single-file components.
|
||||
|
||||
### Update component imports
|
||||
|
||||
Replace all instances of `Livewire\Volt\Component` with `Livewire\Component`:
|
||||
|
||||
@boostsnippet('Volt Import Update', 'php')
|
||||
// Before (Volt)
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component { ... }
|
||||
|
||||
// After (Livewire v4)
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component { ... }
|
||||
@endboostsnippet
|
||||
|
||||
### Remove Volt service provider
|
||||
|
||||
Delete the Volt service provider file:
|
||||
|
||||
@boostsnippet('Remove Volt Provider', 'bash')
|
||||
rm app/Providers/VoltServiceProvider.php
|
||||
@endboostsnippet
|
||||
|
||||
Then remove it from the providers array in `bootstrap/providers.php`:
|
||||
|
||||
@boostsnippet('Update Providers Array', 'php')
|
||||
// Before
|
||||
return [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\VoltServiceProvider::class,
|
||||
];
|
||||
|
||||
// After
|
||||
return [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
];
|
||||
@endboostsnippet
|
||||
|
||||
### Remove Volt package
|
||||
|
||||
Uninstall the Volt package:
|
||||
|
||||
@boostsnippet('Uninstall Volt', 'bash')
|
||||
composer remove livewire/volt
|
||||
@endboostsnippet
|
||||
|
||||
### Install Livewire v4
|
||||
|
||||
After completing the above changes, install Livewire v4. Your existing Volt class-based components will work without modification since they use the same syntax as Livewire's single-file components.
|
||||
|
||||
## New features in v4
|
||||
|
||||
Livewire v4 introduces several powerful new features you can start using immediately:
|
||||
|
||||
### Component features
|
||||
|
||||
**Single-file and multi-file components**
|
||||
|
||||
v4 introduces new component formats alongside the traditional class-based approach. Single-file components combine PHP and Blade in one file, while multi-file components organize PHP, Blade, JavaScript, and tests in a directory.
|
||||
|
||||
By default, view-based component files are prefixed with a ⚡ emoji to distinguish them from regular Blade files in your editor and searches. This can be disabled via the `make_command.emoji` config.
|
||||
|
||||
@boostsnippet('Make Livewire Commands', 'bash')
|
||||
php artisan make:livewire create-post # Single-file (default)
|
||||
php artisan make:livewire create-post --mfc # Multi-file
|
||||
php artisan livewire:convert create-post # Convert between formats
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about component formats →](/docs/4.x/components)
|
||||
|
||||
**Slots and attribute forwarding**
|
||||
|
||||
Components now support slots and automatic attribute bag forwarding using `@{{ $attributes }}`, making component composition more flexible.
|
||||
|
||||
[Learn more about nesting components →](/docs/4.x/nesting)
|
||||
|
||||
**JavaScript in view-based components**
|
||||
|
||||
View-based components can now include `<script>` tags without the `@@script` wrapper. These scripts are served as separate cached files for better performance and automatic `$wire` binding:
|
||||
|
||||
@boostsnippet('JavaScript in Components', 'blade')
|
||||
<div>
|
||||
<!-- Your component template -->
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// $wire is automatically bound as 'this'
|
||||
this.count++ // Same as $wire.count++
|
||||
|
||||
// $wire is still available if preferred
|
||||
$wire.save()
|
||||
</script>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about JavaScript in components →](/docs/4.x/javascript)
|
||||
|
||||
### Islands
|
||||
|
||||
Islands allow you to create isolated regions within a component that update independently, dramatically improving performance without creating separate child components.
|
||||
|
||||
@boostsnippet('Islands Example', 'blade')
|
||||
@@island(name: 'stats', lazy: true)
|
||||
<div>@{{ $this->expensiveStats }}</div>
|
||||
@@endisland
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about islands →](/docs/4.x/islands)
|
||||
|
||||
### Loading improvements
|
||||
|
||||
**Deferred loading**
|
||||
|
||||
In addition to lazy loading (viewport-based), components can now be deferred to load immediately after the initial page load:
|
||||
|
||||
@boostsnippet('Deferred Loading Blade', 'blade')
|
||||
<livewire:revenue defer />
|
||||
@endboostsnippet
|
||||
|
||||
@boostsnippet('Deferred Loading PHP', 'php')
|
||||
#[Defer]
|
||||
class Revenue extends Component { ... }
|
||||
@endboostsnippet
|
||||
|
||||
**Bundled loading**
|
||||
|
||||
Control whether multiple lazy/deferred components load in parallel or bundled together:
|
||||
|
||||
@boostsnippet('Bundled Loading Blade', 'blade')
|
||||
<livewire:revenue lazy.bundle />
|
||||
<livewire:expenses defer.bundle />
|
||||
@endboostsnippet
|
||||
|
||||
@boostsnippet('Bundled Loading PHP', 'php')
|
||||
#[Lazy(bundle: true)]
|
||||
class Revenue extends Component { ... }
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about lazy and deferred loading →](/docs/4.x/lazy)
|
||||
|
||||
### Async actions
|
||||
|
||||
Run actions in parallel without blocking other requests using the `.async` modifier or `#[Async]` attribute:
|
||||
|
||||
@boostsnippet('Async Actions Blade', 'blade')
|
||||
<button wire:click.async="logActivity">Track</button>
|
||||
@endboostsnippet
|
||||
|
||||
@boostsnippet('Async Actions PHP', 'php')
|
||||
#[Async]
|
||||
public function logActivity() { ... }
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about async actions →](/docs/4.x/actions#parallel-execution-with-async)
|
||||
|
||||
### New directives and modifiers
|
||||
|
||||
**`wire:sort` - Drag-and-drop sorting**
|
||||
|
||||
Built-in support for sortable lists with drag-and-drop:
|
||||
|
||||
@boostsnippet('Wire Sort', 'blade')
|
||||
<ul wire:sort="updateOrder">
|
||||
@@foreach ($items as $item)
|
||||
<li wire:sort:item="@{{ $item->id }}" wire:key="@{{ $item->id }}">@{{ $item->name }}</li>
|
||||
@@endforeach
|
||||
</ul>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about wire:sort →](/docs/4.x/wire-sort)
|
||||
|
||||
**`wire:intersect` - Viewport intersection**
|
||||
|
||||
Run actions when elements enter or leave the viewport, similar to Alpine's [`x-intersect`](https://alpinejs.dev/plugins/intersect):
|
||||
|
||||
@boostsnippet('Wire Intersect', 'blade')
|
||||
<!-- Basic usage -->
|
||||
<div wire:intersect="loadMore">...</div>
|
||||
|
||||
<!-- With modifiers -->
|
||||
<div wire:intersect.once="trackView">...</div>
|
||||
<div wire:intersect:leave="pauseVideo">...</div>
|
||||
<div wire:intersect.half="loadMore">...</div>
|
||||
<div wire:intersect.full="startAnimation">...</div>
|
||||
|
||||
<!-- With options -->
|
||||
<div wire:intersect.margin.200px="loadMore">...</div>
|
||||
<div wire:intersect.threshold.50="trackScroll">...</div>
|
||||
@endboostsnippet
|
||||
|
||||
Available modifiers:
|
||||
- `.once` - Fire only once
|
||||
- `.half` - Wait until half is visible
|
||||
- `.full` - Wait until fully visible
|
||||
- `.threshold.X` - Custom visibility percentage (0-100)
|
||||
- `.margin.Xpx` or `.margin.X%` - Intersection margin
|
||||
|
||||
[Learn more about wire:intersect →](/docs/4.x/wire-intersect)
|
||||
|
||||
**`wire:ref` - Element references**
|
||||
|
||||
Easily reference and interact with elements in your template:
|
||||
|
||||
@boostsnippet('Wire Ref', 'blade')
|
||||
<div wire:ref="modal">
|
||||
<!-- Modal content -->
|
||||
</div>
|
||||
|
||||
<button wire:click="$js.scrollToModal">Scroll to modal</button>
|
||||
|
||||
<script>
|
||||
this.$js.scrollToModal = () => {
|
||||
this.$refs.modal.scrollIntoView()
|
||||
}
|
||||
</script>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about wire:ref →](/docs/4.x/wire-ref)
|
||||
|
||||
**`.renderless` modifier**
|
||||
|
||||
Skip component re-rendering directly from the template:
|
||||
|
||||
@boostsnippet('Renderless Modifier', 'blade')
|
||||
<button wire:click.renderless="trackClick">Track</button>
|
||||
@endboostsnippet
|
||||
|
||||
This is an alternative to the `#[Renderless]` attribute for actions that don't need to update the UI.
|
||||
|
||||
**`.preserve-scroll` modifier**
|
||||
|
||||
Preserve scroll position during updates to prevent layout jumps:
|
||||
|
||||
@boostsnippet('Preserve Scroll', 'blade')
|
||||
<button wire:click.preserve-scroll="loadMore">Load More</button>
|
||||
@endboostsnippet
|
||||
|
||||
**`data-loading` attribute**
|
||||
|
||||
Every element that triggers a network request automatically receives a `data-loading` attribute, making it easy to style loading states with Tailwind:
|
||||
|
||||
@boostsnippet('Data Loading', 'blade')
|
||||
<button wire:click="save" class="data-loading:opacity-50 data-loading:pointer-events-none">
|
||||
Save Changes
|
||||
</button>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about loading states →](/docs/4.x/loading-states)
|
||||
|
||||
### JavaScript improvements
|
||||
|
||||
**`$errors` magic property**
|
||||
|
||||
Access your component's error bag from JavaScript:
|
||||
|
||||
@boostsnippet('Errors Magic Property', 'blade')
|
||||
<div wire:show="$errors.has('email')">
|
||||
<span wire:text="$errors.first('email')"></span>
|
||||
</div>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about validation →](/docs/4.x/validation)
|
||||
|
||||
**`$intercept` magic**
|
||||
|
||||
Intercept and modify Livewire requests from JavaScript:
|
||||
|
||||
@boostsnippet('Intercept Magic', 'blade')
|
||||
<script>
|
||||
this.$intercept('save', ({ ... }) => {
|
||||
// ...
|
||||
})
|
||||
</script>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about JavaScript interceptors →](/docs/4.x/javascript#interceptors)
|
||||
|
||||
**Island targeting from JavaScript**
|
||||
|
||||
Trigger island renders directly from the template:
|
||||
|
||||
@boostsnippet('Island Targeting', 'blade')
|
||||
<button wire:click="loadMore" wire:island.append="stats">
|
||||
Load more
|
||||
</button>
|
||||
@endboostsnippet
|
||||
|
||||
[Learn more about islands →](/docs/4.x/islands)
|
||||
|
||||
## Getting help
|
||||
|
||||
If you encounter issues during the upgrade:
|
||||
|
||||
- Check the [documentation](https://livewire.laravel.com) for detailed feature guides
|
||||
- Visit the [GitHub discussions](https://github.com/livewire/livewire/discussions) for community support
|
||||
53
vendor/laravel/boost/src/Mcp/Resources/ApplicationInfo.php
vendored
Normal file
53
vendor/laravel/boost/src/Mcp/Resources/ApplicationInfo.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Resources;
|
||||
|
||||
use Laravel\Boost\Mcp\ToolExecutor;
|
||||
use Laravel\Boost\Mcp\Tools\ApplicationInfo as ApplicationInfoTool;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Resource;
|
||||
|
||||
class ApplicationInfo extends Resource
|
||||
{
|
||||
public function __construct(protected ToolExecutor $toolExecutor)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource's description.
|
||||
*/
|
||||
protected string $description = 'Comprehensive application information including PHP version, Laravel version, database engine, all installed packages with their versions in the application.';
|
||||
|
||||
/**
|
||||
* The resource's URI.
|
||||
*/
|
||||
protected string $uri = 'file://instructions/application-info.md';
|
||||
|
||||
/**
|
||||
* The resource's MIME type.
|
||||
*/
|
||||
protected string $mimeType = 'text/markdown';
|
||||
|
||||
/**
|
||||
* Handle the resource request.
|
||||
*/
|
||||
public function handle(): Response
|
||||
{
|
||||
$response = $this->toolExecutor->execute(ApplicationInfoTool::class);
|
||||
|
||||
if ($response->isError()) {
|
||||
return $response; // Return the error response directly
|
||||
}
|
||||
|
||||
$data = json_decode((string) $response->content(), true);
|
||||
|
||||
if (! $data) {
|
||||
return Response::error('Error parsing application information');
|
||||
}
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
}
|
||||
140
vendor/laravel/boost/src/Mcp/ToolExecutor.php
vendored
Normal file
140
vendor/laravel/boost/src/Mcp/ToolExecutor.php
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp;
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Illuminate\Support\Env;
|
||||
use Laravel\Boost\Support\CommandNormalizer;
|
||||
use Laravel\Mcp\Response;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
use Symfony\Component\Process\Exception\ProcessTimedOutException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class ToolExecutor
|
||||
{
|
||||
public function execute(string $toolClass, array $arguments = []): Response
|
||||
{
|
||||
if (! ToolRegistry::isToolAllowed($toolClass)) {
|
||||
return Response::error("Tool not registered or not allowed: {$toolClass}");
|
||||
}
|
||||
|
||||
return $this->executeInSubprocess($toolClass, $arguments);
|
||||
}
|
||||
|
||||
protected function executeInSubprocess(string $toolClass, array $arguments): Response
|
||||
{
|
||||
$command = $this->buildCommand($toolClass, $arguments);
|
||||
|
||||
// We need to 'unset' env vars that will be passed from the parent process to the child process, stopping the child process from reading .env and getting updated values
|
||||
$env = (Dotenv::create(
|
||||
Env::getRepository(),
|
||||
app()->environmentPath(),
|
||||
app()->environmentFile()
|
||||
))->safeLoad();
|
||||
|
||||
$cleanEnv = array_fill_keys(array_keys($env), false);
|
||||
|
||||
$process = new Process(
|
||||
command: $command,
|
||||
env: $cleanEnv,
|
||||
timeout: $this->getTimeout($arguments)
|
||||
);
|
||||
|
||||
try {
|
||||
$process->mustRun();
|
||||
|
||||
$output = $process->getOutput();
|
||||
$decoded = json_decode($output, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return Response::error('Invalid JSON output from tool process: '.json_last_error_msg());
|
||||
}
|
||||
|
||||
return $this->reconstructResponse($decoded);
|
||||
} catch (ProcessTimedOutException) {
|
||||
$process->stop();
|
||||
|
||||
return Response::error("Tool execution timed out after {$this->getTimeout($arguments)} seconds");
|
||||
|
||||
} catch (ProcessFailedException) {
|
||||
$errorOutput = $process->getErrorOutput().$process->getOutput();
|
||||
|
||||
return Response::error("Process tool execution failed: {$errorOutput}");
|
||||
}
|
||||
}
|
||||
|
||||
protected function getTimeout(array $arguments): int
|
||||
{
|
||||
$timeout = (int) ($arguments['timeout'] ?? 180);
|
||||
|
||||
return max(1, min(600, $timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstruct a Response from JSON data.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function reconstructResponse(array $data): Response
|
||||
{
|
||||
if (! isset($data['isError']) || ! isset($data['content'])) {
|
||||
return Response::error('Invalid tool response format.');
|
||||
}
|
||||
|
||||
if ($data['isError']) {
|
||||
$errorText = 'Unknown error';
|
||||
|
||||
if (is_array($data['content']) && ! empty($data['content'])) {
|
||||
$firstContent = $data['content'][0] ?? [];
|
||||
|
||||
if (is_array($firstContent)) {
|
||||
$errorText = $firstContent['text'] ?? $errorText;
|
||||
}
|
||||
}
|
||||
|
||||
return Response::error($errorText);
|
||||
}
|
||||
|
||||
// Handle array format - extract text content
|
||||
if (is_array($data['content']) && ! empty($data['content'])) {
|
||||
$firstContent = $data['content'][0] ?? [];
|
||||
|
||||
if (is_array($firstContent)) {
|
||||
$text = $firstContent['text'] ?? '';
|
||||
|
||||
$decoded = json_decode((string) $text, true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||
return Response::json($decoded);
|
||||
}
|
||||
|
||||
return Response::text($text);
|
||||
}
|
||||
}
|
||||
|
||||
return Response::text('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the command array for executing a tool in a subprocess.
|
||||
*
|
||||
* @param array<string, mixed> $arguments
|
||||
* @return array<string>
|
||||
*/
|
||||
protected function buildCommand(string $toolClass, array $arguments): array
|
||||
{
|
||||
$phpBinary = config('boost.executable_paths.php') ?? PHP_BINARY;
|
||||
$normalized = CommandNormalizer::normalize($phpBinary);
|
||||
|
||||
return [
|
||||
$normalized['command'],
|
||||
...$normalized['args'],
|
||||
base_path('artisan'),
|
||||
'boost:execute-tool',
|
||||
$toolClass,
|
||||
base64_encode(json_encode($arguments)),
|
||||
];
|
||||
}
|
||||
}
|
||||
88
vendor/laravel/boost/src/Mcp/ToolRegistry.php
vendored
Normal file
88
vendor/laravel/boost/src/Mcp/ToolRegistry.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp;
|
||||
|
||||
use DirectoryIterator;
|
||||
|
||||
class ToolRegistry
|
||||
{
|
||||
/** @var array<int, class-string>|null */
|
||||
private static ?array $cachedTools = null;
|
||||
|
||||
/**
|
||||
* Get all available tools based on the discovery logic from Boost server.
|
||||
*
|
||||
* @return array<int, class-string>
|
||||
*/
|
||||
public static function getAvailableTools(): array
|
||||
{
|
||||
if (self::$cachedTools !== null) {
|
||||
return self::$cachedTools;
|
||||
}
|
||||
|
||||
$tools = [];
|
||||
|
||||
// Discover tools from the Tools directory
|
||||
$excludedTools = config('boost.mcp.tools.exclude', []);
|
||||
$toolDir = new DirectoryIterator(__DIR__.DIRECTORY_SEPARATOR.'Tools');
|
||||
|
||||
foreach ($toolDir as $toolFile) {
|
||||
if ($toolFile->isFile() && $toolFile->getExtension() === 'php') {
|
||||
$fqdn = 'Laravel\\Boost\\Mcp\\Tools\\'.$toolFile->getBasename('.php');
|
||||
|
||||
if (class_exists($fqdn) && ! in_array($fqdn, $excludedTools, true)) {
|
||||
$tools[] = $fqdn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add extra tools from configuration
|
||||
$extraTools = config('boost.mcp.tools.include', []);
|
||||
|
||||
foreach ($extraTools as $toolClass) {
|
||||
if (class_exists($toolClass) && ! in_array($toolClass, $tools, true)) {
|
||||
$tools[] = $toolClass;
|
||||
}
|
||||
}
|
||||
|
||||
self::$cachedTools = $tools;
|
||||
|
||||
return $tools;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a tool class is allowed to be executed.
|
||||
*/
|
||||
public static function isToolAllowed(string $toolClass): bool
|
||||
{
|
||||
return in_array($toolClass, self::getAvailableTools(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cached tools (useful for testing or when configuration changes).
|
||||
*/
|
||||
public static function clearCache(): void
|
||||
{
|
||||
self::$cachedTools = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tool names (class basenames) mapped to their full class names.
|
||||
*
|
||||
* @return array<string, class-string>
|
||||
*/
|
||||
public static function getToolNames(): array
|
||||
{
|
||||
$tools = self::getAvailableTools();
|
||||
$names = [];
|
||||
|
||||
foreach ($tools as $toolClass) {
|
||||
$name = class_basename($toolClass);
|
||||
$names[$name] = $toolClass;
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
}
|
||||
39
vendor/laravel/boost/src/Mcp/Tools/ApplicationInfo.php
vendored
Normal file
39
vendor/laravel/boost/src/Mcp/Tools/ApplicationInfo.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Laravel\Roster\Package;
|
||||
use Laravel\Roster\Roster;
|
||||
|
||||
#[IsReadOnly]
|
||||
class ApplicationInfo extends Tool
|
||||
{
|
||||
public function __construct(protected Roster $roster)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Get comprehensive application information including PHP version, Laravel version, database engine, and all installed packages with their versions. You should use this tool on each new chat, and use the package & version data to write version specific code for the packages that exist.';
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
return Response::json([
|
||||
'php_version' => PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION,
|
||||
'laravel_version' => app()->version(),
|
||||
'database_engine' => config('database.default'),
|
||||
'packages' => $this->roster->packages()->map(fn (Package $package): array => ['roster_name' => $package->name(), 'version' => $package->version(), 'package_name' => $package->rawName()]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
71
vendor/laravel/boost/src/Mcp/Tools/BrowserLogs.php
vendored
Normal file
71
vendor/laravel/boost/src/Mcp/Tools/BrowserLogs.php
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Laravel\Boost\Concerns\ReadsLogs;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
class BrowserLogs extends Tool
|
||||
{
|
||||
use ReadsLogs;
|
||||
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Read the last N log entries from the BROWSER log. Very helpful for debugging the frontend and JS/Javascript';
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'entries' => $schema->integer()
|
||||
->description('Number of log entries to return.')
|
||||
->required(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$maxEntries = $request->integer('entries');
|
||||
|
||||
if ($maxEntries <= 0) {
|
||||
return Response::error('The "entries" argument must be greater than 0.');
|
||||
}
|
||||
|
||||
// Locate the correct log file using the shared helper.
|
||||
$logFile = storage_path('logs'.DIRECTORY_SEPARATOR.'browser.log');
|
||||
|
||||
if (! file_exists($logFile)) {
|
||||
return Response::error('No log file found, probably means no logs yet.');
|
||||
}
|
||||
|
||||
$entries = $this->readLastLogEntries($logFile, $maxEntries);
|
||||
|
||||
if ($entries === []) {
|
||||
return Response::text('Unable to retrieve log entries, or no logs');
|
||||
}
|
||||
|
||||
$logs = implode("\n\n", $entries);
|
||||
|
||||
if (empty(trim($logs))) {
|
||||
return Response::text('No log entries yet.');
|
||||
}
|
||||
|
||||
return Response::text($logs);
|
||||
}
|
||||
}
|
||||
32
vendor/laravel/boost/src/Mcp/Tools/DatabaseConnections.php
vendored
Normal file
32
vendor/laravel/boost/src/Mcp/Tools/DatabaseConnections.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
class DatabaseConnections extends Tool
|
||||
{
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'List the configured database connection names for this application.';
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$connections = array_keys(config('database.connections', []));
|
||||
|
||||
return Response::json([
|
||||
'default_connection' => config('database.default'),
|
||||
'connections' => $connections,
|
||||
]);
|
||||
}
|
||||
}
|
||||
133
vendor/laravel/boost/src/Mcp/Tools/DatabaseQuery.php
vendored
Normal file
133
vendor/laravel/boost/src/Mcp/Tools/DatabaseQuery.php
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Throwable;
|
||||
|
||||
#[IsReadOnly]
|
||||
class DatabaseQuery extends Tool
|
||||
{
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Execute a read-only SQL query against the configured database.';
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'query' => $schema->string()
|
||||
->description('The SQL query to execute. Only read-only queries are allowed (i.e. SELECT, SHOW, EXPLAIN, DESCRIBE).')
|
||||
->required(),
|
||||
'database' => $schema->string()
|
||||
->description("Optional database connection name to use. Defaults to the application's default connection."),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$query = trim((string) $request->string('query'));
|
||||
$token = strtok(ltrim($query), " \t\n\r");
|
||||
|
||||
if (! $token) {
|
||||
return Response::error('Please pass a valid query');
|
||||
}
|
||||
|
||||
$firstWord = strtoupper($token);
|
||||
|
||||
// Allowed read-only commands.
|
||||
$allowList = [
|
||||
'SELECT',
|
||||
'SHOW',
|
||||
'EXPLAIN',
|
||||
'DESCRIBE',
|
||||
'DESC',
|
||||
'WITH', // SELECT must follow Common-table expressions
|
||||
'VALUES', // Returns literal values
|
||||
'TABLE', // PostgresSQL shorthand for SELECT *
|
||||
];
|
||||
|
||||
$isReadOnly = in_array($firstWord, $allowList, true);
|
||||
|
||||
// Additional validation for WITH … SELECT.
|
||||
if ($firstWord === 'WITH') {
|
||||
if (! preg_match('/\)\s*SELECT\b/i', $query)) {
|
||||
$isReadOnly = false;
|
||||
}
|
||||
|
||||
if (preg_match('/\)\s*(DELETE|UPDATE|INSERT|DROP|ALTER|TRUNCATE|REPLACE|RENAME|CREATE)\b/i', $query)) {
|
||||
$isReadOnly = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $isReadOnly) {
|
||||
return Response::error('Only read-only queries are allowed (SELECT, SHOW, EXPLAIN, DESCRIBE, DESC, WITH … SELECT).');
|
||||
}
|
||||
|
||||
$connectionName = $request->get('database');
|
||||
|
||||
try {
|
||||
$connection = DB::connection($connectionName);
|
||||
$prefix = $connection->getTablePrefix();
|
||||
|
||||
if ($prefix) {
|
||||
$query = $this->addPrefixToQuery($query, $prefix);
|
||||
}
|
||||
|
||||
return Response::json(
|
||||
$connection->select($query)
|
||||
);
|
||||
} catch (Throwable $throwable) {
|
||||
return Response::error('Query failed: '.$throwable->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPrefixToQuery(string $query, string $prefix): string
|
||||
{
|
||||
$cteNames = $this->extractCteNames($query);
|
||||
|
||||
$pattern = '/\b(FROM|JOIN|INTO|UPDATE|TABLE|DESCRIBE|DESC)\s+([`"\']?)(\w+)\2/i';
|
||||
|
||||
return preg_replace_callback($pattern, function (array $matches) use ($prefix, $cteNames): string {
|
||||
$keyword = $matches[1];
|
||||
$quote = $matches[2];
|
||||
$tableName = $matches[3];
|
||||
|
||||
if (str_starts_with($tableName, $prefix) || in_array($tableName, $cteNames, true)) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
return "{$keyword} {$quote}{$prefix}{$tableName}{$quote}";
|
||||
}, $query) ?? $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract CTE (Common Table Expression) names from a query.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
protected function extractCteNames(string $query): array
|
||||
{
|
||||
if (preg_match_all('/\b(\w+)\s*(?:\([^)]*\))?\s*AS\s*\(/i', $query, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
271
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema.php
vendored
Normal file
271
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema.php
vendored
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Laravel\Boost\Mcp\Tools\DatabaseSchema\SchemaDriverFactory;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
class DatabaseSchema extends Tool
|
||||
{
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Read the database schema for this application. Returns table names, columns, indexes, and foreign keys. Use "summary" mode first to get an overview (table names with column types only), then call again without "summary" and with a "filter" to get full details for specific tables. Params: "summary" (default false) - returns only table names and column types; "database" - connection name; "filter" - substring match on table names; "include_column_details" (default false) - adds nullable, default, auto_increment, comments; "include_views" (default false); "include_routines" (default false) - stored procedures, functions, sequences.';
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'summary' => $schema->boolean()
|
||||
->description('Return only table names and their column types. Use this first to understand the database structure, then request full details for specific tables using "filter". Defaults to false.'),
|
||||
'database' => $schema->string()
|
||||
->description("Name of the database connection to dump (defaults to app's default connection, often not needed)"),
|
||||
'filter' => $schema->string()
|
||||
->description('Filter tables by name (substring match).'),
|
||||
'include_views' => $schema->boolean()
|
||||
->description('Include database views. Defaults to false.'),
|
||||
'include_routines' => $schema->boolean()
|
||||
->description('Include stored procedures, functions, and sequences. Defaults to false.'),
|
||||
'include_column_details' => $schema->boolean()
|
||||
->description('Include full column metadata (nullable, default, auto_increment, comments, generation). Defaults to false.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$summary = $request->get('summary', false);
|
||||
$connection = $request->get('database') ?? config('database.default');
|
||||
$filter = $request->get('filter') ?? '';
|
||||
$includeViews = $request->get('include_views', false);
|
||||
$includeRoutines = $request->get('include_routines', false);
|
||||
$includeColumnDetails = $request->get('include_column_details', false);
|
||||
|
||||
$cacheKey = sprintf(
|
||||
'boost:mcp:database-schema:%s:%s:%d:%d:%d:%d',
|
||||
$connection,
|
||||
$filter,
|
||||
(int) $summary,
|
||||
(int) $includeViews,
|
||||
(int) $includeRoutines,
|
||||
(int) $includeColumnDetails
|
||||
);
|
||||
|
||||
$schema = rescue(
|
||||
fn () => Cache::remember($cacheKey, 20, fn (): array => $this->getDatabaseStructure(
|
||||
$connection,
|
||||
$filter,
|
||||
$summary,
|
||||
$includeViews,
|
||||
$includeRoutines,
|
||||
$includeColumnDetails
|
||||
)),
|
||||
fn (): array => $this->getDatabaseStructure($connection, $filter, $summary, $includeViews, $includeRoutines, $includeColumnDetails),
|
||||
report: false
|
||||
);
|
||||
|
||||
return Response::json($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{engine: string, tables: array<string, mixed>, views?: array<mixed>, routines?: array{stored_procedures: array<mixed>, functions: array<mixed>, sequences: array<mixed>}}
|
||||
*/
|
||||
protected function getDatabaseStructure(
|
||||
?string $connection,
|
||||
string $filter = '',
|
||||
bool $summary = false,
|
||||
bool $includeViews = false,
|
||||
bool $includeRoutines = false,
|
||||
bool $includeColumnDetails = false
|
||||
): array {
|
||||
$result = [
|
||||
'engine' => DB::connection($connection)->getDriverName(),
|
||||
'tables' => $summary
|
||||
? $this->getAllTableColumnTypes($connection, $filter)
|
||||
: $this->getAllTablesStructure($connection, $filter, $includeColumnDetails),
|
||||
];
|
||||
|
||||
if ($summary) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$driver = SchemaDriverFactory::make($connection);
|
||||
|
||||
if ($includeViews) {
|
||||
$result['views'] = $driver->getViews();
|
||||
}
|
||||
|
||||
if ($includeRoutines) {
|
||||
$result['routines'] = [
|
||||
'stored_procedures' => $driver->getStoredProcedures(),
|
||||
'functions' => $driver->getFunctions(),
|
||||
'sequences' => $driver->getSequences(),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
protected function getAllTablesStructure(?string $connection, string $filter = '', bool $includeColumnDetails = false): array
|
||||
{
|
||||
$structures = [];
|
||||
|
||||
foreach ($this->getAllTables($connection) as $table) {
|
||||
$tableName = is_object($table) ? $table->name : ($table['name'] ?? '');
|
||||
|
||||
if ($filter !== '' && ! str_contains(strtolower($tableName), strtolower($filter))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$structures[$tableName] = $this->getTableStructure($connection, $tableName, $includeColumnDetails);
|
||||
}
|
||||
|
||||
return $structures;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
protected function getAllTableColumnTypes(?string $connection, string $filter = ''): array
|
||||
{
|
||||
$tables = [];
|
||||
|
||||
foreach ($this->getAllTables($connection) as $table) {
|
||||
$tableName = is_object($table) ? $table->name : ($table['name'] ?? '');
|
||||
|
||||
if ($filter !== '' && ! str_contains(strtolower($tableName), strtolower($filter))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tables[$tableName] = collect(Schema::connection($connection)->getColumns($tableName))
|
||||
->pluck('type', 'name')
|
||||
->all();
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, object|array<string, mixed>>
|
||||
*/
|
||||
protected function getAllTables(?string $connection): array
|
||||
{
|
||||
return SchemaDriverFactory::make($connection)->getTables();
|
||||
}
|
||||
|
||||
protected function getTableStructure(?string $connection, string $tableName, bool $includeColumnDetails = false): array
|
||||
{
|
||||
$driver = SchemaDriverFactory::make($connection);
|
||||
|
||||
try {
|
||||
$columns = $this->getTableColumns($connection, $tableName, $includeColumnDetails);
|
||||
$indexes = $this->getTableIndexes($connection, $tableName);
|
||||
$foreignKeys = $this->getTableForeignKeys($connection, $tableName);
|
||||
$triggers = $driver->getTriggers($tableName);
|
||||
$checkConstraints = $driver->getCheckConstraints($tableName);
|
||||
|
||||
return [
|
||||
'columns' => $columns,
|
||||
'indexes' => $indexes,
|
||||
'foreign_keys' => $foreignKeys,
|
||||
'triggers' => $triggers,
|
||||
'check_constraints' => $checkConstraints,
|
||||
];
|
||||
} catch (Exception $exception) {
|
||||
Log::error('Failed to get table structure for: '.$tableName, [
|
||||
'error' => $exception->getMessage(),
|
||||
'trace' => $exception->getTraceAsString(),
|
||||
]);
|
||||
|
||||
return [
|
||||
'error' => 'Failed to get structure: '.$exception->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{type: string, nullable?: bool, default?: mixed, auto_increment?: bool, comment?: string, generation?: array<string, mixed>}>
|
||||
*/
|
||||
protected function getTableColumns(?string $connection, string $tableName, bool $includeColumnDetails = false): array
|
||||
{
|
||||
$schema = Schema::connection($connection);
|
||||
$columnDetails = [];
|
||||
|
||||
foreach ($schema->getColumns($tableName) as $column) {
|
||||
$detail = ['type' => $column['type']];
|
||||
|
||||
if ($includeColumnDetails) {
|
||||
$detail['nullable'] = $column['nullable'];
|
||||
$detail['default'] = $column['default'];
|
||||
$detail['auto_increment'] = $column['auto_increment'];
|
||||
|
||||
if ($column['comment'] !== null && $column['comment'] !== '') {
|
||||
$detail['comment'] = $column['comment'];
|
||||
}
|
||||
|
||||
if ($column['generation'] !== null) {
|
||||
$detail['generation'] = $column['generation'];
|
||||
}
|
||||
}
|
||||
|
||||
$columnDetails[$column['name']] = $detail;
|
||||
}
|
||||
|
||||
return $columnDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{columns: mixed, type: mixed, is_unique: bool, is_primary: bool}>
|
||||
*/
|
||||
protected function getTableIndexes(?string $connection, string $tableName): array
|
||||
{
|
||||
try {
|
||||
$indexDetails = [];
|
||||
|
||||
foreach (Schema::connection($connection)->getIndexes($tableName) as $index) {
|
||||
$indexDetails[$index['name']] = [
|
||||
'columns' => Arr::get($index, 'columns'),
|
||||
'type' => Arr::get($index, 'type'),
|
||||
'is_unique' => Arr::get($index, 'unique', false),
|
||||
'is_primary' => Arr::get($index, 'primary', false),
|
||||
];
|
||||
}
|
||||
|
||||
return $indexDetails;
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
protected function getTableForeignKeys(?string $connection, string $tableName): array
|
||||
{
|
||||
try {
|
||||
return Schema::connection($connection)->getForeignKeys($tableName);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
32
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/DatabaseSchemaDriver.php
vendored
Normal file
32
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/DatabaseSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
abstract class DatabaseSchemaDriver
|
||||
{
|
||||
public function __construct(protected ?string $connection = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
protected function hasTable(?string $table): bool
|
||||
{
|
||||
return $table !== null && $table !== '';
|
||||
}
|
||||
|
||||
abstract public function getViews(): array;
|
||||
|
||||
abstract public function getStoredProcedures(): array;
|
||||
|
||||
abstract public function getFunctions(): array;
|
||||
|
||||
abstract public function getTriggers(?string $table = null): array;
|
||||
|
||||
abstract public function getCheckConstraints(string $table): array;
|
||||
|
||||
abstract public function getSequences(): array;
|
||||
|
||||
abstract public function getTables(): array;
|
||||
}
|
||||
89
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/MySQLSchemaDriver.php
vendored
Normal file
89
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/MySQLSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MySQLSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT TABLE_NAME as name, VIEW_DEFINITION as definition
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('SHOW PROCEDURE STATUS WHERE Db = DATABASE()');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('SHOW FUNCTION STATUS WHERE Db = DATABASE()');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
try {
|
||||
if ($this->hasTable($table)) {
|
||||
return DB::connection($this->connection)->select('SHOW TRIGGERS WHERE `Table` = ?', [$table]);
|
||||
}
|
||||
|
||||
return DB::connection($this->connection)->select('SHOW TRIGGERS');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT CONSTRAINT_NAME, CHECK_CLAUSE
|
||||
FROM information_schema.CHECK_CONSTRAINTS
|
||||
WHERE CONSTRAINT_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = ?
|
||||
', [$table]);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT TABLE_NAME as name
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_TYPE = "BASE TABLE"
|
||||
ORDER BY TABLE_NAME
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
43
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/NullSchemaDriver.php
vendored
Normal file
43
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/NullSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
class NullSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
116
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/PostgreSQLSchemaDriver.php
vendored
Normal file
116
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/PostgreSQLSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PostgreSQLSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT schemaname, viewname, definition
|
||||
FROM pg_views
|
||||
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT proname, prosrc, proargnames, prorettype
|
||||
FROM pg_proc p
|
||||
JOIN pg_namespace n ON p.pronamespace = n.oid
|
||||
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
AND prokind = 'p'
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT proname, prosrc, proargnames, prorettype
|
||||
FROM pg_proc p
|
||||
JOIN pg_namespace n ON p.pronamespace = n.oid
|
||||
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
AND prokind = 'f'
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
try {
|
||||
$sql = '
|
||||
SELECT trigger_name, event_manipulation, event_object_table, action_statement
|
||||
FROM information_schema.triggers
|
||||
WHERE trigger_schema = current_schema()
|
||||
';
|
||||
|
||||
if ($this->hasTable($table)) {
|
||||
$sql .= ' AND event_object_table = ?';
|
||||
|
||||
return DB::connection($this->connection)->select($sql, [$table]);
|
||||
}
|
||||
|
||||
return DB::connection($this->connection)->select($sql);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT conname, pg_get_constraintdef(oid) as definition
|
||||
FROM pg_constraint
|
||||
WHERE contype = 'c'
|
||||
AND conrelid = ?::regclass
|
||||
", [$table]);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT sequence_name, start_value, minimum_value, maximum_value, increment
|
||||
FROM information_schema.sequences
|
||||
WHERE sequence_schema = current_schema()
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT tablename as name
|
||||
FROM pg_tables
|
||||
WHERE schemaname = current_schema()
|
||||
ORDER BY tablename
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
76
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SQLiteSchemaDriver.php
vendored
Normal file
76
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SQLiteSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SQLiteSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT name, sql
|
||||
FROM sqlite_master
|
||||
WHERE type = 'view'
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT name, sql FROM sqlite_master WHERE type = 'trigger'";
|
||||
|
||||
if ($this->hasTable($table)) {
|
||||
$sql .= ' AND tbl_name = ?';
|
||||
|
||||
return DB::connection($this->connection)->select($sql, [$table]);
|
||||
}
|
||||
|
||||
return DB::connection($this->connection)->select($sql);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT name
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table'
|
||||
AND name NOT LIKE 'sqlite_%'
|
||||
ORDER BY name
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SchemaDriverFactory.php
vendored
Normal file
27
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SchemaDriverFactory.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SchemaDriverFactory
|
||||
{
|
||||
public static function make(?string $connection = null): DatabaseSchemaDriver
|
||||
{
|
||||
$connectionName = $connection ?? config('database.default');
|
||||
$driverName = config("database.connections.{$connectionName}.driver");
|
||||
|
||||
if (! is_string($driverName) || $driverName === '') {
|
||||
$driverName = DB::connection($connectionName)->getDriverName();
|
||||
}
|
||||
|
||||
return match ($driverName) {
|
||||
'mysql', 'mariadb' => new MySQLSchemaDriver($connection),
|
||||
'pgsql' => new PostgreSQLSchemaDriver($connection),
|
||||
'sqlite' => new SQLiteSchemaDriver($connection),
|
||||
default => new NullSchemaDriver($connection),
|
||||
};
|
||||
}
|
||||
}
|
||||
55
vendor/laravel/boost/src/Mcp/Tools/GetAbsoluteUrl.php
vendored
Normal file
55
vendor/laravel/boost/src/Mcp/Tools/GetAbsoluteUrl.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
class GetAbsoluteUrl extends Tool
|
||||
{
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Get the absolute URL for a given relative path or named route. If no arguments are provided, you will get the absolute URL for "/"';
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'path' => $schema->string()
|
||||
->description('The relative URL/path (e.g. "/dashboard") to convert to an absolute URL.'),
|
||||
'route' => $schema->string()
|
||||
->description('The named route to generate an absolute URL for (e.g. "home").'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$path = $request->get('path');
|
||||
$routeName = $request->get('route');
|
||||
|
||||
if ($path) {
|
||||
return Response::text(url($path));
|
||||
}
|
||||
|
||||
if ($routeName) {
|
||||
return Response::text(route($routeName));
|
||||
}
|
||||
|
||||
return Response::text(url('/'));
|
||||
}
|
||||
}
|
||||
85
vendor/laravel/boost/src/Mcp/Tools/LastError.php
vendored
Normal file
85
vendor/laravel/boost/src/Mcp/Tools/LastError.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Illuminate\Log\Events\MessageLogged;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Boost\Concerns\ReadsLogs;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
class LastError extends Tool
|
||||
{
|
||||
use ReadsLogs;
|
||||
|
||||
/**
|
||||
* Indicates whether the Log listener has been registered for this process.
|
||||
*/
|
||||
private static bool $listenerRegistered = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Register the listener only once per PHP process.
|
||||
if (! self::$listenerRegistered) {
|
||||
Log::listen(function (MessageLogged $event): void {
|
||||
if ($event->level === 'error') {
|
||||
rescue(fn () => Cache::forever('boost:last_error', [
|
||||
'timestamp' => now()->toDateTimeString(),
|
||||
'level' => $event->level,
|
||||
'message' => $event->message,
|
||||
'context' => [], // $event->context,
|
||||
]), report: false);
|
||||
}
|
||||
});
|
||||
|
||||
self::$listenerRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Get details of the last error/exception created in this application on the backend. Use browser-log tool for browser errors.';
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
// First, attempt to retrieve the cached last error captured during runtime.
|
||||
// This works even if the log driver isn't a file driver, so is the preferred approach
|
||||
$cached = rescue(fn () => Cache::get('boost:last_error'), report: false);
|
||||
|
||||
if ($cached) {
|
||||
$entry = "[{$cached['timestamp']}] {$cached['level']}: {$cached['message']}";
|
||||
|
||||
if (! empty($cached['context'])) {
|
||||
$entry .= ' '.json_encode($cached['context']);
|
||||
}
|
||||
|
||||
return Response::text($entry);
|
||||
}
|
||||
|
||||
// Locate the correct log file using the shared helper.
|
||||
$logFile = $this->resolveLogFilePath();
|
||||
|
||||
if (! file_exists($logFile)) {
|
||||
return Response::error("Log file not found at {$logFile}");
|
||||
}
|
||||
|
||||
$entry = $this->readLastErrorEntry($logFile);
|
||||
|
||||
if ($entry !== null) {
|
||||
return Response::text(Str::limit($entry, 500, '... more logs', true));
|
||||
}
|
||||
|
||||
return Response::error('Unable to find an ERROR entry in the inspected portion of the log file.');
|
||||
}
|
||||
}
|
||||
73
vendor/laravel/boost/src/Mcp/Tools/ReadLogEntries.php
vendored
Normal file
73
vendor/laravel/boost/src/Mcp/Tools/ReadLogEntries.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Laravel\Boost\Concerns\ReadsLogs;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
class ReadLogEntries extends Tool
|
||||
{
|
||||
use ReadsLogs;
|
||||
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = 'Read the last N log entries from the application log, correctly handling multi-line PSR-3 formatted logs and JSON-formatted logs. Only works for log files.';
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'entries' => $schema->integer()
|
||||
->description('Number of log entries to return.')
|
||||
->required(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$maxEntries = (int) $request->get('entries');
|
||||
|
||||
if ($maxEntries <= 0) {
|
||||
return Response::error('The "entries" argument must be greater than 0.');
|
||||
}
|
||||
|
||||
// Determine log file path via helper.
|
||||
$logFile = $this->resolveLogFilePath();
|
||||
|
||||
if (! file_exists($logFile)) {
|
||||
return Response::error("Log file not found at {$logFile}");
|
||||
}
|
||||
|
||||
$entries = $this->readLastLogEntries($logFile, $maxEntries);
|
||||
|
||||
if ($entries === []) {
|
||||
return Response::text('Unable to retrieve log entries, or no entries yet.');
|
||||
}
|
||||
|
||||
$logs = implode("\n\n", $entries);
|
||||
|
||||
if (empty(trim($logs))) {
|
||||
return Response::text('No log entries yet.');
|
||||
}
|
||||
|
||||
return Response::text($logs);
|
||||
}
|
||||
|
||||
// The isNewLogEntry and readLinesReverse helper methods are now provided by the ReadsLogs trait.
|
||||
}
|
||||
143
vendor/laravel/boost/src/Mcp/Tools/SearchDocs.php
vendored
Normal file
143
vendor/laravel/boost/src/Mcp/Tools/SearchDocs.php
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools;
|
||||
|
||||
use Generator;
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Laravel\Boost\Concerns\MakesHttpRequests;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Roster\Package;
|
||||
use Laravel\Roster\Roster;
|
||||
use Throwable;
|
||||
|
||||
class SearchDocs extends Tool
|
||||
{
|
||||
use MakesHttpRequests;
|
||||
|
||||
public function __construct(protected Roster $roster)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* The tool's description.
|
||||
*/
|
||||
protected string $description = "Search for up-to-date version-specific documentation related to this project and its packages. This tool will search Laravel hosted documentation based on the packages installed and is perfect for all Laravel ecosystem packages. Laravel, Inertia, Pest, Livewire, Filament, Nova, Tailwind, and more. You must use this tool to search for Laravel-ecosystem docs before using other approaches. The results provided are for this project's package version and does not cover all versions of the package.";
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'queries' => $schema->array()
|
||||
->items($schema->string()->description('Search query'))
|
||||
->description('List of queries to perform, pass multiple if you aren\'t sure if it is "toggle" or "switch", for example')
|
||||
->required(),
|
||||
'packages' => $schema->array()
|
||||
->items($schema->string()->description("The composer package name (e.g., 'symfony/console')"))
|
||||
->description('Package names to limit searching to from application-info. Useful if you know the package(s) you need. i.e. laravel/framework, inertiajs/inertia-laravel, @inertiajs/react'),
|
||||
'token_limit' => $schema->integer()
|
||||
->description('Maximum number of tokens to return in the response. Defaults to 3,000 tokens, maximum 1,000,000 tokens. If results are truncated, or you need more complete documentation, increase this value (e.g.5000, 10000)'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response|Generator
|
||||
{
|
||||
$apiUrl = config('boost.hosted.api_url', 'https://boost.laravel.com').'/api/docs';
|
||||
|
||||
$packagesFilter = $this->resolveArrayParam($request->get('packages'));
|
||||
|
||||
if ($packagesFilter instanceof Response) {
|
||||
return $packagesFilter;
|
||||
}
|
||||
|
||||
$rawQueries = $this->resolveArrayParam($request->get('queries'));
|
||||
|
||||
if ($rawQueries instanceof Response) {
|
||||
return $rawQueries;
|
||||
}
|
||||
|
||||
$queries = array_filter(
|
||||
array_map(trim(...), $rawQueries),
|
||||
fn (string $query): bool => $query !== '' && $query !== '*'
|
||||
);
|
||||
|
||||
try {
|
||||
$packagesCollection = $this->roster->packages();
|
||||
|
||||
// Only search in specific packages
|
||||
if ($packagesFilter) {
|
||||
$packagesCollection = $packagesCollection->filter(fn (Package $package): bool => in_array($package->rawName(), $packagesFilter, true));
|
||||
}
|
||||
|
||||
$packages = $packagesCollection->map(function (Package $package): array {
|
||||
$name = $package->rawName();
|
||||
$version = $package->majorVersion().'.x';
|
||||
|
||||
return [
|
||||
'name' => $name,
|
||||
'version' => $version,
|
||||
];
|
||||
});
|
||||
|
||||
$packages = $packages->values()->toArray();
|
||||
} catch (Throwable $throwable) {
|
||||
return Response::error('Failed to get packages: '.$throwable->getMessage());
|
||||
}
|
||||
|
||||
$tokenLimit = $request->get('token_limit') ?? 3000;
|
||||
$tokenLimit = min($tokenLimit, 1000000); // Cap at 1M tokens
|
||||
|
||||
$payload = [
|
||||
'queries' => $queries,
|
||||
'packages' => $packages,
|
||||
'token_limit' => $tokenLimit,
|
||||
'format' => 'markdown',
|
||||
];
|
||||
|
||||
try {
|
||||
$response = $this->client()->asJson()->post($apiUrl, $payload);
|
||||
|
||||
if (! $response->successful()) {
|
||||
return Response::error('Failed to search documentation: '.$response->body());
|
||||
}
|
||||
} catch (Throwable $throwable) {
|
||||
return Response::error('HTTP request failed: '.$throwable->getMessage());
|
||||
}
|
||||
|
||||
return Response::text($response->body());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>|null|Response
|
||||
*/
|
||||
private function resolveArrayParam(mixed $value): array|null|Response
|
||||
{
|
||||
if (! is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$decoded = json_decode($value, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return Response::error('Invalid parameter: '.json_last_error_msg());
|
||||
}
|
||||
|
||||
if (! is_array($decoded) || ! array_is_list($decoded)) {
|
||||
return Response::error('Invalid parameter: expected a JSON array.');
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user