based/laravel-typescript
Composer 安装命令:
composer require based/laravel-typescript
包简介
Transform Laravel models into TypeScript interfaces
关键字:
README 文档
README
The package lets you generate TypeScript interfaces from your Laravel models.
Introduction
Say you have a model which has several properties (database columns) and multiple relations.
class Product extends Model { public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function features(): HasMany { return $this->hasMany(Feature::class); } }
Laravel TypeScript will generate the following TypeScript interface:
declare namespace App.Models { export interface Product { id: number; category_id: number; name: string; price: number; created_at: string | null; updated_at: string | null; category?: App.Models.Category | null; features?: Array<App.Models.Feature> | null; } ... }
Laravel TypeScript supports:
- Database columns
- Model relations
- Model accessors
- Casted attributes
Installation
Laravel 8 and PHP 8 are required. You can install the package via composer:
composer require based/laravel-typescript
You can publish the config file with:
php artisan vendor:publish --provider="Based\TypeScript\TypeScriptServiceProvider" --tag="typescript-config"
This is the contents of the published config file:
return [ 'generators' => [ Model::class => ModelGenerator::class, ], 'output' => resource_path('js/models.d.ts'), // load namespaces from composer's `dev-autoload` 'autoloadDev' => false, ];
Usage
Generate TypeScript interfaces.
php artisan typescript:generate
Example usage with Vue 3:
import { defineComponent, PropType } from "vue"; export default defineComponent({ props: { product: { type: Object as PropType<App.Models.Product>, required: true, }, }, }
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
based/laravel-typescript 适用场景与选型建议
based/laravel-typescript 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 155.8k 次下载、GitHub Stars 达 399, 最近一次更新时间为 2021 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「typescript」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 based/laravel-typescript 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 based/laravel-typescript 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 based/laravel-typescript 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generate typescript rpc from php
Transforms Laravel Models to Typescript Interfaces/Types
Minimal Laravel authentication scaffolding with Vue, Vite, Typescript and Tailwind.
End-to-end type-safe APIs for Laravel. Like tRPC, but for Laravel + TypeScript.
Config-driven CRUD scaffolding for Laravel + Inertia.js (React/TypeScript) with interactive generator, built-in search, filters, sorting, export, import, and role-based permissions.
Alfabank REST API integration
统计信息
- 总下载量: 155.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 399
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-25