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, register the service provider in config/app.php:
Orchestra\Canvas\LaravelServiceProvider::class,
This replaces Laravel’s default make: commands with Canvas-enhanced versions.
First Use Case: Generate a migration and model in one command (Laravel preset):
vendor/bin/canvas make:model Post -m
Or for a package (after setting up canvas.yaml):
vendor/bin/canvas make:job ProcessOrder --namespace="PackageName\Jobs"
Quick Preset Setup: For Laravel:
vendor/bin/canvas preset laravel
For a package (replace PackageName):
vendor/bin/canvas preset package --namespace="PackageName"
canvas.yaml: Central configuration file for namespaces, paths, and stub customization.vendor/orchestra/canvas/stubs/, override these to modify generated files.vendor/bin/canvas list to see all available commands (mirrors Laravel’s make: commands).canvas.yaml to define project-wide namespaces (e.g., App\Modules\Auth).
preset: laravel
namespace: App\Modules
model:
namespace: App\Modules\{ModuleName}
# Generate a module-specific model + migration
vendor/bin/canvas make:model Auth/User -m --namespace="Auth"
--force to overwrite existing files during refactoring.canvas.yaml to isolate package namespaces and paths.
preset: package
namespace: PackageName
paths:
src: src
resource: resources
# Generate a job with package-specific namespace
vendor/bin/canvas make:job ProcessPayment --namespace="PackageName\Jobs"
composer exec canvas in package composer.json scripts for CI/CD:
"scripts": {
"generate:tests": "canvas make:test UserTest --namespace=\"PackageName\\Tests\""
}
stubs/ directory (create if missing) to inject project-specific logic.
Example: Modify model.stub to auto-add soft deletes:
<?php
namespace {{namespace}};
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class {{name}} extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
}
vendor/orchestra/canvas/stubs/model.stub to stubs/model.stub.--alias to create custom command shortcuts in canvas.yaml:
aliases:
make:crud: "make:model make:migration make:controller make:resource"
vendor/bin/canvas make:crud Post
Expands to 4 commands automatically.# .github/workflows/scaffolding.yml
jobs:
scaffold:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: composer exec canvas make:test UserTest --namespace="App\\Tests"
--dry-run to preview changes without writing files:
vendor/bin/canvas make:model Post -m --dry-run
&& for multi-step scaffolding:
vendor/bin/canvas make:model Post -m && vendor/bin/canvas make:controller PostController --resource
php artisan make:model directly—Canvas overrides the default behavior.Namespace Conflicts:
canvas.yaml is misconfigured.namespace and paths sections in canvas.yaml. Use --namespace flag to override per command:
vendor/bin/canvas make:job ProcessOrder --namespace="App\Jobs"
Stub Overrides Not Applied:
stubs/ are ignored.app/ or src/). Restart the CLI if changes aren’t reflected.Hidden Commands:
make:migration) may not appear in canvas list.vendor/bin/canvas make:migration CreatePostsTable --create
Laravel Service Provider Clash:
Orchestra\Canvas\LaravelServiceProvider, default make: commands may behave unexpectedly.composer dump-autoload or restart your IDE/terminal. Use php artisan list to confirm Canvas commands are registered.PHP Version Mismatch:
v10.1.1+ (released for PHP 8.5 compatibility).-v or --verbose to debug command execution:
vendor/bin/canvas make:model Post -vv
{{ dump() }} to stubs to inspect variables during generation:
{{ dump() }}
namespace {{namespace}};
vendor/bin/canvas --version
php artisan --version
Ensure both point to the same Laravel version.Custom Commands:
MakeCrudCommand) and register it in canvas.yaml:
commands:
make:crud: App\Console\Commands\MakeCrudCommand
Dynamic Stub Injection:
stubs config to load stubs from a custom path:
// config/canvas.php
'stubs' => [
'model' => resource_path('stubs/model.stub'),
],
Preset Templates:
canvas.yaml and sharing them across projects. Example:
# .canvas-preset/auth.yaml
preset: package
namespace: AuthPackage
model:
namespace: AuthPackage\Models
IDE Integration:
vendor/bin/canvas as an external tool.Illuminate\Filesystem\join_paths() for path resolution. Ensure paths in canvas.yaml are relative to the project root.canvas.yaml are case-sensitive. Use App\Models instead of app\models.canvas.yaml is missing, Canvas falls back to Laravel’s defaults. Explicitly define the preset (preset: laravel or preset: package) to avoid surprises.vendor/orchestra/canvas/cache/. Clear the cache with:
vendor/bin/canvas cache:clear
Useful after stub modifications.for model in User Post Category; do
vendor/bin/canvas make:model "$model" -m
done
How can I help you explore Laravel packages today?