flow96/laravel-bridge
Composer 安装命令:
composer require flow96/laravel-bridge
包简介
A Laravel package that bridges Laravel APIs with TypeScript clients using OpenAPI generation
README 文档
README
Laravel Bridge is a powerful package that seamlessly connects your Laravel API with TypeScript clients by automatically generating type-safe client code from your OpenAPI schemas. Built on top of Laravel Scramble, it provides an effortless way to maintain synchronization between your backend API and frontend client code.
Laravel Bridge uses under the hood:
- Laravel Scramble for OpenAPI schema generation
- @hey-api/openapi-ts for OpenAPI schema generation
For detailed configuration options see Laravel Scramble and @hey-api/openapi-ts.
Features
- 🚀 Automatic TypeScript Client Generation: Generate fully typed TypeScript clients from your Laravel API
- 📡 Real-time Watching: Monitor schema changes and regenerate clients automatically
- 🔧 Highly Configurable: Customize output directories, client types, and generation options
- 🎯 Laravel Scramble Integration: Leverages the power of Laravel Scramble for OpenAPI schema generation
- 💼 Multiple Client Types: Support for fetch, axios, xhr, and node HTTP clients
- 🛡️ Type Safety: Full TypeScript type definitions for your API endpoints
- ⚡ Zero Configuration: Works out of the box with sensible defaults
Installation
Prerequisites
Before using Laravel Bridge, ensure you have:
- Node.js installed
- Composer installed
- Laravel Api Routes installed (
php artisan install:api)
Install Laravel API
php artisan install:api
Install the Bridge package
You can install the package via Composer:
composer require flow96/laravel-bridge
Publishing the configuration
Laravel Bridge uses Scramble under the hood to generate the OpenAPI schema.
By publishing the configuration you can modify the Laravel Bridge configuration in config/bridge.php, and the Scramble configuration in config/scramble.php.
- Publish the configuration:
php artisan vendor:publish --tag=bridge-config
Usage
Basic Commands
Scramble (the openapi schema generator) works by default only if your app is running in the local environment.
Run your application
Your app must be running with the local environment in order for scramble to be able to generate the OpenAPI schema.
php artisan serve
Generate TypeScript Client
Generate a TypeScript client from your OpenAPI schema:
php artisan bridge:generate
Generate the client into a different directory for a single run:
php artisan bridge:generate --output=../frontend/src/api/client
To make the output directory persistent, set it in your .env file:
BRIDGE_CLIENT_OUTPUT=../frontend/src/api/client
You can also set an absolute or computed path in config/bridge.php:
'output' => base_path('../frontend/src/api/client'),
Using the Generated Client
After running the generate command, you'll find TypeScript files in your configured output directory. Here's how to use them:
With Axios client (default)
import { UserService } from './client/sdk.gen'; // Create a new user const result = await UserService.create({ body: { name: "John Doe", email: "asd@asd.com", password: "superSecret" } }) // Get all users const users = await UserService.getAll(); console.log(users.data.users);
Best Practices
1. API Documentation
For the best results, ensure your Laravel controllers are well-documented:
public function index(Request $request): JsonResponse { $users = User::all(); // Type hint is necessary for Eloquent models /** @var App\Models\User[] */ return response(users); } public function index(Request $request): JsonResponse { $users = User::all(); // Resources work out of the box return response(UserResource::collection($users)); } // Parameters of the form request are automatically transformed into typescript types public function store(CreateUserRequest $request): JsonResponse { $user = User::create($request->validated()); return response(UserResource::make($user), 201); } public function findByName(Request $request): JsonResponse { // Query parameters are automatically transformed into typescript types $name = $request->query('name'); $user = User::where('name', $name)->first(); return response(UserResource::make($user)); }
2. Resource Classes
Use Eloquent API Resources for consistent response formatting:
class UserResource extends JsonResource { public function toArray($request): array { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; } }
Credits
- Laravel Scramble for OpenAPI generation
- OpenAPI TypeScript for client generation
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG for more information on what has changed recently.
flow96/laravel-bridge 适用场景与选型建议
flow96/laravel-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「client」 「Bridge」 「laravel」 「openapi」 「typescript」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flow96/laravel-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flow96/laravel-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flow96/laravel-bridge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Soluble PHP Java bridge integration
Bridge between JMS Serializer Bundle and Superdesk Web Publisher.
A PSR-7 compatible library for making CRUD API endpoints
Builds a Bridge between Zend Expressive and Plugin Managers of Zend\MVC
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-23