定制 illuma-law/laravel-wayfinder-forge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

illuma-law/laravel-wayfinder-forge

最新稳定版本:v0.1.4

Composer 安装命令:

composer require illuma-law/laravel-wayfinder-forge

包简介

Auto-generate strongly typed frontend SDKs from Laravel Wayfinder routes.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Auto-generate strongly typed frontend SDKs from your Laravel backend routes and FormRequests.

Wayfinder Forge ensures your frontend client code stays perfectly in sync with your backend validation rules. It parses your Laravel routes, reflects on their FormRequest or Spatie\Data classes, and automatically generates a ready-to-use TypeScript SDK.

Features

  • TypeScript Interface Generation: Automatically converts Laravel validation rules (required, string, nullable, array) into accurate TypeScript interfaces.
  • Spatie Laravel Data Support: First-class support for spatie/laravel-data DTOs.
  • Multiple Client Support: Generates SDKs formatted for axios, standard fetch, or inertia.
  • Customizable Output: Easily define which routes to include/exclude via prefixes and middleware filters.

Installation

You can install the package via composer:

composer require illuma-law/laravel-wayfinder-forge --dev

Publish the config file:

php artisan vendor:publish --tag="laravel-wayfinder-forge-config"

Configuration

The published config/wayfinder-forge.php allows you to customize the output behavior:

return [
    /**
     * The output path for the generated TypeScript SDK file.
     */
    'output_path' => resource_path('js/api/sdk.ts'),

    /**
     * Define which routes should be processed.
     */
    'routes' => [
        // Only include routes matching these prefixes
        'include_prefixes' => [
            'api/*',
        ],

        // Exclude routes with specific middleware (like internal debug tools)
        'exclude_middlewares' => [
            'debugbar',
        ],
    ],

    /**
     * The HTTP client template to use for the generated SDK.
     * Supported: 'axios', 'fetch', 'inertia'
     */
    'client' => 'axios',

    /**
     * Enable support for spatie/laravel-data objects.
     */
    'use_spatie_data' => true,
];

Usage & Integration

Generate your TypeScript SDK by running the forge command:

php artisan wayfinder:forge

Tip: Add this command to your package.json build scripts so it runs automatically during development.

Example: FormRequests

Laravel Controller & Request

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StorePostRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'title' => 'required|string|max:255',
            'content' => 'required|string',
            'is_published' => 'boolean', // Optional by default unless 'required' is present
        ];
    }
}

// routes/api.php
Route::post('api/posts', [PostController::class, 'store'])->name('posts.store');

Generated TypeScript SDK (resources/js/api/sdk.ts)

export interface ApiPostsRequest {
    title: string;
    content: string;
    is_published?: boolean;
}

export const postsStore = (data: ApiPostsRequest) => {
    return axios.post(`/api/posts`, data);
};

Example: Spatie Laravel Data

If you are using spatie/laravel-data to type-hint your controllers instead of FormRequests, Forge handles that automatically.

Laravel Controller & Data Object

namespace App\Data;

use Spatie\LaravelData\Data;

class UserData extends Data
{
    public string $name;
    public ?int $age;
}

// routes/api.php
Route::post('api/users', function (UserData $userData) { 
    // ...
});

Generated TypeScript SDK

export interface UserData {
    name: string;
    age?: number;
}

export const apiUsers = (data: UserData) => {
    return axios.post(`/api/users`, data);
};

Testing

Run the package tests:

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固