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

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

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

saher/artisan-schematics

最新稳定版本:v1.3.0

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

统计信息

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

GitHub 信息

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

其他信息

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