Installation Add the bundle via Composer:
composer require draw/draw-bundle
Enable it in config/bundles.php:
return [
// ...
Draw\DrawBundle\DrawBundle::class => ['all' => true],
];
First Use Case: CLI Commands Run the built-in commands to explore functionality:
php bin/console draw:list # List available commands
php bin/console draw:make:controller UserController # Generate a controller
Where to Look First
src/Command/ for available CLI tools.src/Twig/ for reusable Twig helpers.src/Doctrine/ for ORM utilities.Code Generation
Use draw:make:controller, draw:make:entity, or draw:make:form to scaffold boilerplate:
php bin/console draw:make:controller Admin/DashboardController --resource=Post
Tip: Customize templates in vendor/draw/draw-bundle/Resources/skeleton/.
Database Utilities Reset migrations or generate SQL dumps:
php bin/console draw:db:reset
php bin/console draw:db:dump --path=./backup.sql
Extend templates with custom filters/extensions:
{{ 'hello'|draw_uppercase }}
{{ draw_asset('css/style.css') }} {# Optimized asset handling #}
Register in config/packages/draw.yaml:
draw:
twig:
extensions: ['App\Twig\CustomExtension']
draw:make:entity with --fields to auto-generate CRUD fields:
php bin/console draw:make:entity Product --fields="name:string,price:decimal(10,2)"
Draw\Doctrine\BaseRepository.Centralize settings in config/packages/draw.yaml:
draw:
generators:
namespace: 'App\\Generator' # Custom generator namespace
assets:
version: 'v1.2' # Asset cache versioning
Outdated Package Last release in 2019—verify compatibility with Symfony 5/6/Laravel (if using via Symfony bridge). Override deprecated features with custom logic.
Namespace Collisions
The bundle’s generators use Draw\ namespace. Prepend your custom generators with App\Generator\ in draw.yaml to avoid conflicts.
Twig Cache Issues Clear Twig cache after adding extensions:
php bin/console cache:clear
Command Errors
Run with -v for verbose output:
php bin/console draw:make:controller -v
Check var/log/dev.log for Doctrine/Twig errors.
Asset Pipeline
If draw_asset() fails, ensure assets config is set in draw.yaml:
draw:
assets:
base_urls: ['%kernel.project_dir%/public/build']
Custom Commands
Extend existing commands by overriding their classes (e.g., Draw\Command\MakeControllerCommand) in your bundle.
Twig Filters
Add filters by implementing Twig\Extension\AbstractExtension and registering in draw.yaml:
draw:
twig:
filters:
- { name: 'custom_filter', class: 'App\Twig\CustomFilter' }
Doctrine Events
Subscribe to draw.entity.generate events to modify entity generation dynamically:
// config/services.yaml
services:
App\EventListener\DrawEntityListener:
tags:
- { name: 'kernel.event_listener', event: 'draw.entity.generate', method: 'onGenerate' }
How can I help you explore Laravel packages today?