orchestra/canvas
Orchestra Canvas brings Laravel’s artisan make:* generators to apps and packages. Generate controllers, models, migrations, jobs, mail, middleware, tests and more, with customizable namespaces and stubs—usable inside or outside a full Laravel install.
Installation:
composer require --dev orchestra/canvas
For Laravel projects, optionally register the service provider in config/app.php under providers:
Orchestra\Canvas\LaravelServiceProvider::class,
Initialize Preset: Choose either:
vendor/bin/canvas preset laravel
vendor/bin/canvas preset package --namespace="Your\Package\Namespace"
This generates a canvas.yaml config file in your project root.
First Use Case: Generate a migration:
vendor/bin/canvas make:migration create_users_table --create=users
Or use composer exec canvas for Laravel environments:
composer exec canvas make:model User
canvas.yaml: Central configuration for namespaces, paths, and stubs.vendor/orchestra/canvas/stubs/. Customize these for project-specific templates.make: commands but work outside Laravel installations.Laravel Integration:
LaravelServiceProvider to override Laravel’s make: commands with Canvas equivalents.php artisan make:model seamlessly—Canvas handles the rest under the hood.Package Development:
make:command) without a Laravel install.canvas.yaml with preset: package and adjust paths (e.g., src, resources).Custom Stubs:
vendor/orchestra/canvas/stubs/ to stubs/ in your project.model.stub to auto-inject traits or interfaces.Workflow Integration:
composer exec canvas make:model Post -m -r -f
Creates a model, migration, resource, and factory in one command.--batch flag for bulk operations (e.g., generating multiple migrations).Testing:
composer exec canvas make:test Unit/FeatureTest --unit
testing.namespace in canvas.yaml for consistency.IDE Support:
vendor/bin/canvas to your IDE’s terminal or task runner for quick access.composer exec canvas in Laravel projects to avoid path issues.CI/CD:
# Example GitHub Actions step
- run: composer exec canvas make:test Unit/UserTest --unit
Team Onboarding:
canvas.yaml conventions in your project’s CONTRIBUTING.md.# Required for all new developers
namespace: App\Modules\Auth
model:
namespace: App\Modules\Auth\Models
Stub Customization:
{# stubs/api-resource.stub #}
namespace {{ namespace }};
use Illuminate\Http\Resources\Json\JsonResource;
class {{ class }} extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
// Add custom fields here
];
}
}
Namespace Conflicts:
canvas.yaml namespaces don’t match your project structure, generated files may fail to autoload.composer dump-autoload runs after generation.Stub Overrides:
stubs/ must match the original filename (e.g., model.stub).canvas:publish to copy stubs to your project:
composer exec canvas publish:stubs
Laravel Service Provider:
LaravelServiceProvider in Laravel projects may cause commands to fall back to Laravel’s defaults.config/app.php:
Orchestra\Canvas\LaravelServiceProvider::class,
Path Resolution:
canvas.yaml (e.g., paths.src) must exist or generation will fail.canvas:make-dirs:
composer exec canvas make-dirs
PHP Version Mismatches:
orchestra/canvas:9.x).Verbose Output:
Use --verbose to debug stub rendering:
composer exec canvas make:model User --verbose
Stub Debugging: Check rendered stubs by inspecting the generated file or using:
composer exec canvas stub:show model
Command Aliases:
Canvas supports Laravel’s AsCommand aliases (e.g., make:controller → make:controller). If aliases don’t work, ensure the service provider is registered.
Preset Management:
--namespace with preset to avoid manual edits:
composer exec canvas preset package --namespace="Acme\Package"
Stub Versioning:
Performance:
composer exec canvas make:migration create_table_1 --create=table1
composer exec canvas make:migration create_table_2 --create=table2
Laravel 11+ Features:
AsCommand and new stub formats (e.g., make:enum).Package Discovery:
Orchestra\Canvas\LaravelServiceProvider is in providers to auto-register commands.Hidden Commands:
canvas list to see all available commands, including hidden ones like make:view.Testing Integration:
--unit or --feature flags for Laravel’s testing conventions:
composer exec canvas make:test Unit/UserTest --unit
Migration Prefixes:
migration.prefix in canvas.yaml to avoid conflicts in multi-module projects:
migration:
prefix: 'auth_'
How can I help you explore Laravel packages today?