vod/laravel-typed-routes
Composer 安装命令:
composer require vod/laravel-typed-routes
包简介
Typescript route generation and TS client for Laravel
README 文档
README
Introduction
This package generates TypeScript types from your Laravel routes, and provides an extensible client for interacting with the routes in a type safe way. It relies on the fantastic Spatie Typescript Transformer under the hood.
Installation
You can install the package via composer:
composer require vod/laravel-typed-routes
You can publish the config file with:
php artisan vendor:publish --tag="laravel-typed-routes-config"
This is the contents of the published config file:
return [ 'output_path' => 'resources/routes.d.ts', ];
This defines where the generated types will be output.
Generating Types
php artisan typescript:transform-routes
This will generate the types and output them to the path defined in the config file. It's recommended That you run this on save or as a part of your front end dev tooling, so that types are kept up to date.
Setup with Typescript
Setup is easy! In your project, you'll need to setup an rpc client, something as simple as this;
/** * This puts together the client with the route types. Depending on where you * publish the routes, and where this file is, you may need to adjust the import. * */ import { Routes } from "./types/routes"; //... A basic client, only exposes a basic fetch wrapper; import { makeBasicClient } from "../../vendor/vod/laravel-typed-routes/js/basicClient"; //... Expects React Query to be installed, and exposes `useQuery` and `useMutation` methods; import {makeReactQueryClient} from "../../vendor/vod/laravel-typed-routes/js/reactQueryClient"; //... Expects Inertia to be installed, and exposes `useForm` and `visit` methods; import { makeInertiaClient } from "../../vendor/vod/laravel-typed-routes/js/inertiaClient"; //... Expects React Query and Inertia to be installed, and exposes `useQuery`, `useMutation`, `useForm`, and `usePage` methods; import { makeFullClient } from "../../vendor/vod/laravel-typed-routes/js/fullClient"; //... Create the client - swap out the client that best suits your needs, or copy any of the clients to extend or modify as you like! export const routes = makeFullClient<Routes>();
Depending on your project, you will need to adjust the paths for the imports.
Using the client
Route navigation
This library automatically converts routes to a type path. For example, the following laravel routes would be accessible as;
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard'); Route::get('/example/{id}/hello', [ExampleController::class, 'hello'])->name('example.hello'); Route::put('/example/{id}/update', [ExampleController::class, 'update'])->name('example.update');
// Routes are automatically converted to a type path. routes.dashboard.get() routes.example.id(idGoesHere).hello.get() routes.example.id(idGoesHere).update.put()
The API chosen will determine the methods available. For example, the full client
exposes useQuery, useMutation, useForm, and usePage methods, so you can
use these methods to interact with the routes like this;
Basic fetch
const response = await routes.example.id(idGoesHere).hello.get().call({ message: 'Hello, world!', });
Inertia
//Inside a component //use Form to update data on the route; const {submit, data, setData} = routes.example.id(idGoesHere).update.post().useForm({ message: 'hello world', }); const goToDashboard = () => { /**The "visit" method calls the inertia router with the full path, * the appropriate method, and any data you want to pass. */ routes.dashboard.get().visit({success: true}); }
@tanstack/react-query
//Inside a component //use Query to fetch data from the route; const { data, isLoading, error } = routes.example.id(idGoesHere).hello.get().useQuery({ message: 'Hello, world!', }); //use Mutation to update data on the route; const { mutate, isLoading, error } = routes.example.id(idGoesHere).update.put().useMutation({ }); mutate({ message: 'hello world' })
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
vod/laravel-typed-routes 适用场景与选型建议
vod/laravel-typed-routes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「vod」 「laravel-typed-routes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vod/laravel-typed-routes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vod/laravel-typed-routes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vod/laravel-typed-routes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-12