saher/artisan-schematics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

saher/artisan-schematics

Composer 安装命令:

composer require saher/artisan-schematics

包简介

Generate model definitions for any language (TypeScript, Dart, Kotlin, etc.) directly from your Laravel backend.

README 文档

README

Tests License Packagist GitHub Repo

Artisan Schematics is the most powerful, extensible, and professional Laravel package for exporting your Eloquent models and PHP enums to TypeScript, Dart, Kotlin, and Swift. It is designed for teams and individuals who want seamless, type-safe, cross-platform development.

🚀 Features

  • Multi-language output: TypeScript, Dart, Kotlin, Swift (easily add more)
  • Deep relationship support: Handles all Eloquent relationships (hasOne, hasMany, belongsTo, belongsToMany, morphTo, morphMany, hasOneThrough, etc.)
  • Enum and custom cast detection
  • Recursive dependency resolution (all referenced models/enums are included)
  • Configurable output paths and language toggles
  • Zero manual require/include: full autoloading
  • Battle-tested: Comprehensive test suite for all features
  • Extensible: Add your own generators in minutes
  • Professional code output: Idiomatic, readable, and ready for production

📦 Installation

composer require saher/artisan-schematics --dev

⚙️ Configuration

Publish the config file:

php artisan vendor:publish --provider="Saher\ArtisanSchematics\ArtisanSchematicsServiceProvider"

Edit config/schematics.php to enable/disable languages and set output paths for each target.

🛠️ Usage

Export all models and enums:

php artisan schematics:export

Or specify custom paths:

php artisan schematics:export --paths=app/Models,app/Enums

📂 Output

  • TypeScript: resource/ts/schemas (default)
  • Dart: tests/output/dart (customizable)
  • Kotlin: tests/output/kotlin (customizable)
  • Swift: tests/output/swift (customizable)

🧠 What gets generated?

  • All models, enums, and their relationships (including advanced: morphs, through, etc.)
  • All referenced types recursively (no missing dependencies)
  • Output files for each language (e.g., Post.ts, PostStatus.dart, User.kt, Tag.swift, etc.)

💡 Example

Models

class User extends Model {
	public function posts() { return $this->hasMany(Post::class); }
	public function tags() { return $this->belongsToMany(Tag::class); }
	public function comments() { return $this->morphMany(Comment::class, 'commentable'); }
	public function country() { return $this->hasOneThrough(Country::class, Address::class); }
}

class Post extends Model {
	protected $casts = [
		'status' => PostStatus::class,
		'tags' => 'array',
	];
	public function author() { return $this->belongsTo(User::class); }
}

class Comment extends Model {
	public function post() { return $this->hasMany(Post::class); }
	public function tags() { return $this->belongsToMany(Tag::class); }
}

class Tag extends Model {}
class Country extends Model {}
class Address extends Model {}

Enum

enum PostStatus: string { case DRAFT = 'draft'; case PUBLISHED = 'published'; }

Output

  • User.ts, Post.ts, Comment.ts, Tag.ts, Country.ts, Address.ts, PostStatus.ts
  • user.dart, post.dart, comment.dart, tag.dart, country.dart, address.dart, post_status.dart
  • User.kt, Post.kt, Comment.kt, Tag.kt, Country.kt, Address.kt, PostStatus.kt
  • User.swift, Post.swift, Comment.swift, Tag.swift, Country.swift, Address.swift, PostStatus.swift

🧪 Testing

Run the test suite:

./vendor/bin/pest

Tests assert that all expected files are generated for all languages, including enums and all relationship types.

🧩 Extending

Add your own generator by implementing GeneratorContract and registering it in config/schematics.php:

'go' => [
	'enabled' => true,
	'generator' => \App\Generators\GoGenerator::class,
	'output_path' => base_path('go/models'),
],

🛠️ Advanced Usage & Tips

  • Custom relationships: All Eloquent relationship types are supported out of the box.
  • Enum support: Backed and pure enums are both supported.
  • Custom casts: Custom cast types are detected and exported.
  • Zero manual require/include: All files are autoloaded and analyzed recursively.
  • CI/CD ready: Add ./vendor/bin/pest to your pipeline to ensure your contracts are always up to date.

❓ Troubleshooting

  • Missing files? Ensure your models/enums are in the scanned paths and autoloaded by Composer.
  • Custom output? Edit config/schematics.php to change output directories or add new languages.
  • Need more? Open an issue or PR!

🤝 Community & Contributing

Pull requests, issues, and feature requests are welcome! Help make Artisan Schematics the standard for cross-platform Laravel development.

📄 License

MIT

📦 Releases & Tags

saher/artisan-schematics 适用场景与选型建议

saher/artisan-schematics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 saher/artisan-schematics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 saher/artisan-schematics 我们能提供哪些服务?
定制开发 / 二次开发

基于 saher/artisan-schematics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-10