Weave Code
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

Entity To Model Bundle Laravel Package

aristonet/entity-to-model-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require aristonet/entity-to-model-bundle
    

    Ensure your project uses Symfony 6.2+ and Doctrine ORM.

  2. First Run: Execute the default command to generate TypeScript models in src/Models/ (default):

    php bin/console convert:entitytomodel
    

    Verify generated files in src/Models/ (or your configured output directory).

  3. First Use Case: Generate a single entity (e.g., Order) with a custom output path:

    php bin/console convert:entitytomodel --className=Order --modelDir=src/Types/
    

    Check src/Types/Order.ts for the generated model.


Implementation Patterns

Workflows

  1. Integrate into Build Process: Add the command to post-install-cmd in composer.json to auto-generate models on dependency updates:

    "scripts": {
        "post-install-cmd": [
            "@php bin/console convert:entitytomodel --modelDir=src/Types/"
        ]
    }
    
  2. Partial Updates: Use --className to regenerate only specific entities (e.g., after schema changes):

    php bin/console convert:entitytomodel --className=User,Product
    
  3. Custom Naming: Override the default EntityName.ts convention by extending the bundle’s template logic (see Extension Points).

Integration Tips

  • Frontend Sync: Use the generated models in your frontend (e.g., React/Vue) by copying src/Types/ to your frontend project’s src/types/ or importing via a monorepo setup.

  • API Contracts: Pair with Symfony’s ApiPlatform to ensure frontend models match API responses. Example:

    // Auto-generated from Doctrine Entity
    interface Order {
      id: number;
      items: OrderItem[];
      createdAt: Date;
    }
    
  • CI/CD: Add the command to your CI pipeline (e.g., GitHub Actions) to validate model consistency:

    - run: php bin/console convert:entitytomodel --modelDir=src/Types/
    - run: git diff --exit-code src/Types/  # Fail if models changed unexpectedly
    

Gotchas and Tips

Pitfalls

  1. Doctrine Metadata Cache: Clear the cache if models aren’t updating:

    php bin/console cache:clear
    php bin/console doctrine:cache:clear-metadata
    
  2. Circular References: The bundle may fail on complex inheritance or circular references (e.g., UserOrder). Exclude problematic entities with --excludeClassName.

  3. TypeScript Version: The generated models use basic TypeScript types. For advanced types (e.g., Pick, Omit), post-process the output with a script or template.

Debugging

  • Verbose Output: Enable debug mode to see skipped entities or errors:

    php bin/console convert:entitytomodel -vvv
    
  • Dry Run: Test the command without writing files:

    php bin/console convert:entitytomodel --dry-run
    

Config Quirks

  • Default Directories: The bundle defaults to src/Models/ for output. Override in config/packages/aristonet_entity_to_model.yaml:

    aristonet_entity_to_model:
        model_dir: '%kernel.project_dir%/src/Types/'
    
  • Excluded Entities: Skip specific entities globally via config:

    aristonet_entity_to_model:
        excluded_classes: ['App\Entity\AuditLog', 'App\Entity\Migration']
    

Extension Points

  1. Custom Templates: Override the default TypeScript template by creating a custom Twig template in templates/entity_to_model/ and configure the bundle to use it:

    aristonet_entity_to_model:
        template: 'custom_entity_to_model.ts.twig'
    
  2. Post-Processing: Use Symfony’s EventDispatcher to hook into the model generation process. Example:

    // src/EventListener/ModelGenerationListener.php
    public function onModelGenerated(ModelGeneratedEvent $event) {
        $content = $event->getContent();
        $content = str_replace('interface', 'type', $content); // Force `type` instead of `interface`
        $event->setContent($content);
    }
    
  3. Dynamic Paths: Generate models in dynamic paths (e.g., per-module) by implementing a custom ModelGenerator service and binding it to the bundle’s aristonet_entity_to_model.model_generator service.

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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver