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

Generator Bundle Laravel Package

ismaambrosi/generator-bundle

A Laravel generator bundle that streamlines scaffolding by creating models, controllers, migrations, and related boilerplate from Artisan commands, reducing repetitive setup and helping you build new application features faster with consistent structure.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install as a dev dependency. composer require --dev ismaambrosi/generator-bundle. As of v2.5.0 the bundle also declares support for Symfony 3, so the constraint you can pin in your root composer.json has widened:

    "symfony/symfony": "~2.7|~2.8|~3.0|~3.4",
    "doctrine/mongodb-odm": "~1.0"
    

    Pin these before requiring the bundle so the solver settles on a compatible Doctrine ODM. Symfony 3 buys you PHP 5.5.9+ rather than the old 5.3 floor, but there is still no support for Symfony 4+ — do not plan to carry this into a modern app without patches.

  2. Register the bundle in the dev (and optionally test) environment of app/AppKernel.php. Generators are tooling, not runtime code, so they do not belong in prod. (AppKernel still exists in Symfony 3; it is only removed in 4.)

  3. Configure DoctrineMongoDBBundle first. The generators read ODM metadata, not the database. You need at least one document manager and a mapping driver with your bundle's mapping path registered:

    doctrine_mongodb:
        document_managers:
            default:
                mappings:
                    AcmeDemoBundle: ~
    

    If doctrine:mongodb:mapping:info is not clean, the generators will emit empty or wrong stubs.

  4. Confirm the commands are visible. The console entry point moved in Symfony 3, so the command differs by version — pick the one that matches your app:

    php app/console list doctrine:mongodb:generate   # Symfony 2.7 / 2.8
    php bin/console list doctrine:mongodb:generate   # Symfony 3.x
    

    If nothing appears, clear the cache (app/console cache:clear or bin/console cache:clear) and re-check bundle registration.

  5. First use case — scaffold one document end to end:

    php bin/console doctrine:mongodb:generate:document AcmeDemoBundle:Product
    php bin/console doctrine:mongodb:generate:form     AcmeDemoBundle:Product
    php bin/console doctrine:mongodb:generate:crud     AcmeDemoBundle:Product --route-prefix=product
    

    Look first at the generated document class (src/Acme/DemoBundle/Document/Product.php) — its mapping is the source of truth for everything the form and CRUD generators produce downstream.

Implementation Patterns

Document → Form → CRUD is a one-way chain. Each generator reads ODM metadata from the document class, not from the database. Get annotations right before generating forms and controllers, or you will regenerate twice.

Annotate types explicitly. The form generator maps ODM field types (int, float, boolean, date, string, collection, hash) to Symfony form types. Anything it cannot map cleanly falls back to TextType — so declare type= on every @MongoDB\Field rather than relying on inference.

Scaffold once, then own the code. Generated controllers, forms and Twig views are a starting point, not a maintained layer. Move pagination, filtering, flash messages and redirect logic into an abstract base controller and a base form type so that re-running a generator only changes the parts you did not customise.

Use the options for multi-document / multi-manager apps. Pass --document-manager when you have more than one DM, and always pass a distinct --route-prefix per document — otherwise generated CRUD routes collide silently.

API-first variant. Skip generate:crud entirely. Use generate:document + generate:form, then expose the form type through FOSRestBundle/serializer so you get validation and hydration without the HTML scaffolding.

Fixtures pairing. Generate the document, then hand-write a LoadProductData fixture against the same class. This avoids duplicating the class definition just to get test data in.

Customise skeletons for house style. Copy the bundle's Resources/skeleton into app/Resources/IsmaAmbrosiGeneratorBundle/skeleton/... (the Sensio-style override mechanism) so generated controllers match your annotation/namespace conventions without forking the bundle.

References and embeds are manual. Generate each referenced document independently, then wire @MongoDB\ReferenceOne / ReferenceMany / EmbedMany by hand — the generator does not produce a correct CollectionType or entity-choice field for these.

Cross-version Symfony 2.7/2.8 → 3.x migration. Because v2.5.0 brings Symfony 3 into the support matrix, an app that already uses these generators can be lifted to 3.x without swapping tooling — but generated controllers target Symfony 2 conventions. Re-generate on the target version rather than committing Symfony-2-style controllers into a Symfony 3 app, and check that generated templates do not use form themes that were removed between 2.8 and 3.0.

Gotchas and Tips

  • Still effectively unmaintained. v2.5.0 is an incremental revival (Symfony 3 support, Travis tweaks, CS fixes) — not a modernisation. There is no Symfony 4/5 support, no PHP 7.2+ hardening. Isolate it in a legacy app or a pinned --dev install; expect to maintain any fork yourself.
  • Console path changed with Symfony 3. If you copy command snippets out of older documentation (or out of your own scripts), app/console will not exist on a Symfony 3 app — use bin/console. Audit CI scripts and Makefiles after the upgrade.
  • Metadata is king — failures are silent. Missing or wrong ODM annotations produce empty forms with no error. Always run doctrine:mongodb:mapping:info before generating.
  • Commit before every generate. Files are overwritten with minimal prompting. A clean git tree turns an overwrite into a reviewable diff.
  • The document generator is interactive (it asks for field types). In CI/scripts, --no-interaction accepts defaults — which may not be the types you want. Prefer generating locally and committing the result.
  • ID field. Mark the identifier @MongoDB\Id; ensure the generated form does not include it. Editing an ObjectId through a text field silently breaks references.
  • Collections. type="collection" comes out as TextType; replace it with CollectionType (allow_add, allow_delete, by_reference => false on the parent).
  • Dates. ODM date maps to \DateTime. A generated DateType yields midnight; use 'widget' => 'single_text' and handle timezone explicitly if you need precision.
  • Routing/views collide when generating several CRUDs. Always set --route-prefix and verify app/config/routing.yml after import.
  • Debugging: php bin/console debug:container | grep -i generator to locate generator services; run commands with -vvv to see which skeleton paths are used. If a command disappears after upgrading to v2.5.0, the bundle registration in AppKernel.php (not the bundle itself) is the usual cause.
  • Security: generated controllers have no access control. Put them behind a firewall or add @Security annotations before shipping.
  • Extension points that survive upgrades: custom generators registered as tagged services extending the bundle's base generator classes, and template overrides under app/Resources. Both let you customise output without forking — and both are the parts most likely to need small signature tweaks against the v2.5.0 base classes.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource