- Can I use orchestra/canvas to generate Laravel code outside a Laravel project (e.g., for package development)?
- Yes, Canvas is designed for standalone package development. It replicates Laravel’s `make:*` commands without requiring a full Laravel installation, letting you scaffold controllers, models, migrations, and more using `canvas make:controller`, `canvas make:migration`, etc. Configure custom namespaces and stubs via `canvas.yaml` for consistency across projects.
- How do I install orchestra/canvas in a Laravel project?
- Run `composer require --dev orchestra/canvas` in your project. For Laravel apps, Canvas automatically overrides Artisan commands (e.g., `make:controller` becomes Canvas-enhanced). Use `composer exec canvas make:controller` to bypass conflicts or run side-by-side with custom commands.
- Does orchestra/canvas support custom stubs for generated files?
- Absolutely. Canvas uses stub templates (e.g., `model.stub`, `migration.stub`) in your project’s `resources/stubs` or a global `canvas.yaml` config. Override defaults for namespaces, annotations, or PHP 8.5+ features like enums. Stub customization is key for non-standard requirements or legacy syntax.
- Which Laravel versions does orchestra/canvas support?
- Canvas officially supports Laravel 11–13 and PHP 8.4–8.5. For older versions (e.g., Laravel 10 or PHP 8.1), you may need custom stubs or a fork. Check the [GitHub repo](https://github.com/orchestral/canvas) for version-specific notes, as major Laravel updates (e.g., 14+) could require Canvas updates.
- Will orchestra/canvas conflict with my existing custom Artisan commands?
- Canvas replaces native `make:*` commands by default. To avoid conflicts, use `composer exec canvas make:controller` explicitly or alias commands in your shell (e.g., `alias make=canvas`). If you’ve extended Laravel’s generators, review Canvas’s stubs or namespace handling to ensure compatibility.
- Can I integrate orchestra/canvas into CI/CD pipelines for auto-generating tests or migrations?
- Yes, Canvas works seamlessly in CI/CD. Use `composer exec canvas make:test` or `canvas make:migration` in scripts. For performance, cache stubs or parallelize generation (e.g., with Laravel Forge). Audit logs can track generated files by parsing Canvas’s output or using `canvas --log` flags.
- How do I customize the namespace or class resolution for generated files?
- Define custom namespaces in `canvas.yaml` under the `namespaces` key or override stubs to include dynamic placeholders like `{namespace}`. For example, set `namespaces: { App\Packages\MyPackage }` to prefix all generated classes. Canvas resolves classes relative to your project’s root or a specified path.
- Are there alternatives to orchestra/canvas for Laravel code generation?
- For Laravel-specific use, consider Laravel’s built-in `make:*` commands or packages like `laravel-shift/blueprint` for advanced scaffolding. For non-Laravel projects, tools like `laravel-zero` (for CLI apps) or `filp/whoops` (for error pages) offer niche solutions. However, Canvas uniquely bridges Laravel conventions with package development workflows.
- How do I test or validate generated code from orchestra/canvas?
- Canvas includes unit tests for core functionality, but validate edge cases (e.g., nested namespaces, custom paths) manually. Use `canvas make:model --test` to generate a model with test stubs, then run `phpunit` on the output. For CI, add a post-generation step to lint or analyze generated files with tools like `phpstan` or `psalm`.
- What’s the best way to manage stub templates across multiple projects?
- Centralize stubs in a monorepo or shared package (e.g., `company/stubs`) and reference them in `canvas.yaml` via `stubs_path`. For per-project customization, override stubs locally while inheriting defaults from the global config. Use version control to track stub changes and avoid drift from Laravel conventions.