nolanos/laravel-model-typescript-transfomer
Pros:
spatie/laravel-typescript-transformer, a battle-tested foundation, ensuring compatibility with Laravel’s Eloquent ORM and existing TypeScript workflows.$hidden/$visible filters, enabling granular control over exposed properties (critical for APIs or sensitive data).Cons:
hasOne/belongsTo types require additional configuration (see spatie’s docs).spatie/laravel-typescript-transformer (v2+) and a Laravel project with Eloquent models.collectors/transformers).typescript:generate) with optional --watch for dev workflows.ALTER TABLE operations may require regenerating types.ModelTransformer).shared-types package), synchronization must be manual or automated via CI.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Schema Drift | High | Implement CI checks (e.g., diff generated types post-migration) or use php artisan migrate:fresh in tests. |
| Type Inaccuracy | Medium | Override ModelTransformer for edge cases (e.g., custom casts, computed attributes). |
| Build Pipeline Impact | Low | Cache generated types (e.g., .gitignore or node_modules) to avoid regenerating on every npm install. |
| Frontend Sync | Medium | Use a shared types package (e.g., @myorg/shared-types) or a post-generation script to copy types to frontend. |
| Performance | Low | Generation is O(n) per model; negligible for typical Laravel apps (<100 models). |
$visible/$hidden configuration.)User + UserProfile)? Nested types may require customization.morphTo) or accessors/mutators? These may not auto-generate correctly.spatie/laravel-typescript-transformer and nolanos/laravel-model-typescript-transfomer.User, Order).main branch pushes).node_modules or a .types directory.| Component | Compatibility Notes |
|---|---|
| Laravel | Tested with Laravel 9+. Ensure spatie/laravel-typescript-transformer is v2+. |
| Eloquent Models | Works with standard models; custom casts may need manual type overrides. |
| Database | Relies on current schema. Migrations require type regeneration. |
| TypeScript | Outputs plain TypeScript interfaces. No framework-specific types (e.g., React hooks). |
| Frontend Frameworks | Agnostic; works with React, Vue, Svelte, etc. |
| Monorepos | May need path aliases or post-generation scripts to sync types. |
spatie/laravel-typescript-transformer installed (v2+).nolanos/laravel-model-typescript-transfomer.config/typescript-transformer.php.php artisan typescript:generate.main or schema changes).node_modules or .gitignore them.php artisan typescript:generate).$hidden/$visible properties and regenerate.$appends or accessors).How can I help you explore Laravel packages today?