Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Oi Laravel Ts Laravel Package

oi-lab/oi-laravel-ts

A Laravel package that automatically generates TypeScript interfaces from your Eloquent models, with relationship support, custom casts, DataObjects, PHPDoc types, watch mode, and namespace filters for customization.

View on GitHub
Deep Wiki
Context7
v1.2.0

Added

  • use_database_schema (default true): model attributes are read from the table. Every column the model serializes is emitted — fillable or not — typed from its cast or, when uncast, from its column type, and marked nullable (col?: T | null) when the column is. Falls back to $fillable when disabled or when the database is unreachable at generation time.
  • declaration_style (default 'interface'): 'type' emits export type IFoo = { ... }; instead of export interface IFoo { ... }. A type alias is assignable to Record<string, T> — what Inertia's useForm / useHttp require — where an interface never is. Extension models become intersections.
  • data_discriminators: emit a DTO as a discriminated union. Given a discriminant property and a map value => DTO class (literal, or a callable resolved at generation time), the DTO comes out as I{X}Base, I{X}{Property}Map and I{X} = I{X}Base & ( | { key: 'a'; prop: IA } | ... ), so narrowing on the discriminant narrows the property. The Record<string, unknown> member that absorbed a [@param](https://github.com/param) A|B|array<string, mixed> union is gone.

Fixed

  • list<T>, non-empty-list<T>, non-empty-array<K, V>, iterable<T> and Collection<K, T> resolve like array<K, T> instead of falling back to unknown without warning.
  • A union nested in a generic (array<int, string|int>) no longer recurses forever.
  • Enum casts on models emit their literal union instead of never.
  • Built-in casts are typed by what they serialize to: int/bool/timestamp/immutable_datetime/decimal:*/hashed/encrypted no longer come out as never; array/json/collection come out as unknown.
  • Hidden attributes ($hidden, #[Hidden]) are left out of model interfaces — they never reach the JSON.
  • A class cast whose value type cannot be read is typed unknown instead of falling back to its column (a json column read as string), and | null is no longer appended to unknown.
  • MorphTo relations are typed unknown and HasOneThrough / HasManyThrough resolve to their related model, instead of never.
  • New-style Attribute accessors listed in $appends are typed from their [@return](https://github.com/return) Attribute<TGet, TSet> annotation, or else from the getter closure's return type, instead of unknown (rendered never).

Changed

  • Generated output — with use_database_schema on, model interfaces gain their non-fillable columns and nullable columns become col?: T | null. Timestamps stay required. Set use_database_schema => false for the previous output.
v1.0.0

Initial release of OI Laravel TypeScript Generator - a comprehensive Laravel package that automatically generates TypeScript interfaces from Eloquent models.

Core Features

  • Automatic Interface Generation: Converts Eloquent models to TypeScript interfaces with full type safety
  • Relationship Support: Handles all Laravel relationship types (HasOne, HasMany, BelongsTo, BelongsToMany, MorphTo, MorphMany, etc.)
  • Custom Casts: Automatic detection and conversion of Laravel custom casts
  • DataObject Support: Analyzes and generates interfaces for PHP DataObject classes
  • PHPDoc Support: Reads PHPDoc annotations for complex types
  • Watch Mode: Monitor models directory and automatically regenerate on changes
  • Configurable Options: Extensive configuration for customization
  • JSON-LD Support: Optional support for JSON-LD data structures
  • Relationship Counts: Automatic generation of _count fields for relationships
  • External Type Imports: Reference and import external TypeScript types

Architecture

Built with clean architecture principles and separation of concerns:

Analysis Pipeline (Eloquent)

  • Eloquent: Facade for model analysis and schema generation
  • ModelDiscovery: Discovers all Eloquent models in the application
  • TypeExtractor: Extracts type information from model properties
  • RelationshipResolver: Detects and extracts relationship metadata
  • CastTypeResolver: Resolves custom Laravel casts to TypeScript types
  • DataObjectAnalyzer: Analyzes PHP DataObject classes
  • PhpToTypeScriptConverter: Converts PHP types to TypeScript
  • SchemaBuilder: Orchestrates complete schema building

Generation Pipeline (Convert)

  • Convert: Main orchestrator coordinating TypeScript generation
  • TypeScriptTypeConverter: Handles schema to TypeScript type conversion
  • DataObjectProcessor: Processes PHP DataObjects and generates interfaces
  • ModelInterfaceGenerator: Generates TypeScript interfaces for models
  • ImportManager: Manages TypeScript import statements
  • JsonLdGenerator: Generates JSON-LD support interfaces

Technical Excellence

  • SOLID Principles: Each class follows Single Responsibility Principle
  • Dependency Injection: Used throughout for better testability
  • Comprehensive Documentation: ~900+ lines of PHPDoc documentation
  • Type Safety: Full PHP type hints with structured array shapes
  • Modular Design: Plugin-like architecture for easy extension
  • Error Handling: Robust error handling throughout pipelines

Requirements

  • PHP 8.2, 8.3, or 8.4
  • Laravel 11.0+ or 12.0+

Testing

  • 39 comprehensive tests with 160 assertions
  • Unit tests for all components
  • Feature tests for integration scenarios
  • Architecture tests for code quality

Command Line Interface

  • php artisan oi:gen-ts - Generate TypeScript interfaces
  • php artisan oi:gen-ts --watch - Watch mode for automatic regeneration

Configuration Options

  • output_path - Custom output path for generated TypeScript
  • with_counts - Include relationship count fields
  • with_json_ld - Enable JSON-LD support
  • save_schema - Save intermediate schema.json for debugging
  • props_with_types - Define specific types for properties
  • custom_props - Add custom properties to models
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo