- Can this package generate Laravel Eloquent models directly from MySQL Workbench (.mwb) files?
- No, this package does not natively support Eloquent. It generates Doctrine 2 annotations or Propel schemas, which would require manual adaptation (e.g., regex or custom scripts) to convert to Eloquent conventions like `$fillable` or `$casts`. For Eloquent, consider post-processing the output or using Laravel’s built-in migrations.
- How do I install this package for Laravel projects?
- Run `composer require --dev comunedifirenze/mysql-workbench-schema-exporter` in your project. For specific exporters (e.g., Doctrine 2), add them separately like `composer require --dev comunedifirenze/doctrine2-exporter`. The CLI tool will be available at `vendor/bin/mysql-workbench-schema-export`.
- Does this work with Laravel 8/9 and PHP 8.0+?
- The package targets PHP 5.4+, but Laravel 8+ requires PHP 8.0+. Test compatibility carefully, especially with Doctrine 2 exporters, as newer PHP features (e.g., typed properties) may need adjustments. Use `--dev` in `composer.json` to avoid runtime conflicts.
- Can I integrate this into Laravel’s Artisan CLI?
- Yes, create a custom Artisan command to wrap the CLI tool. For example, add a `SchemaExporter` command in `app/Console/Commands/` that calls `vendor/bin/mysql-workbench-schema-export` with your preferred exporter (e.g., Doctrine 2). This automates schema generation in your Laravel workflow.
- What formats does this package support for Laravel-compatible ORMs?
- It supports Doctrine 2 (YAML/annotations) and Propel (XML/YAML). Doctrine 2 output can be used with `doctrine/orm` in Laravel, while Propel requires adopting the Propel ORM. For Eloquent, you’d need to manually adapt the generated schemas or write a custom exporter.
- How do I handle schema changes in MySQL Workbench and sync them with Laravel models?
- Re-run the exporter CLI with your updated `.mwb` file to regenerate schemas. For Doctrine, use `doctrine orm:schema-tool:update` to apply changes. For Eloquent, manually merge changes or automate it with a script comparing old/new schemas. Always back up your database before updates.
- Are there alternatives for Laravel-specific schema generation?
- Yes, Laravel’s built-in migrations (`php artisan make:migration`) are native but manual. For Doctrine, use `laravel-doctrine/orm` with its schema tools. If you need visual modeling, consider tools like **SchemaCrawler** or **DbSchema**, though they lack MySQL Workbench integration.
- How do I test generated schemas for correctness?
- Validate Doctrine schemas with `doctrine orm:validate-schema`. For Propel, use its built-in validation. Test edge cases (e.g., complex foreign keys) by importing the schema into a test database and running queries. Automate this in CI/CD pipelines to catch issues early.
- Will this package slow down my Laravel application in production?
- No, the exporter is a development tool (installed via `--dev`). It only generates static schema files (e.g., YAML/annotations) during development or deployment. Runtime performance depends on your ORM (Doctrine/Propel), not the exporter itself.
- How do I contribute or extend this package for Laravel support?
- Fork the repository and create a custom exporter plugin for Laravel/Eloquent by extending the base exporter classes. Submit a pull request or use the plugin system to add Laravel-specific formatters. Check the existing exporters (e.g., Doctrine2) for implementation patterns.