orchestra/canvas

Code Generators for Laravel Applications and Packages

Installs: 4 754 813

Dependents: 158

Suggesters: 0

Security: 0

Stars: 193

Watchers: 4

Forks: 12

Open Issues: 0

v9.1.3 2024-10-02 01:00 UTC

README

Canvas replicates all of the make artisan commands available in your basic Laravel application. It allows everyone to use it:

  • outside of Laravel installation such as when building Laravel packages.
  • with Laravel by allowing a few customizations to the stub resolved class and namespace.

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

Installation

To install through composer, run the following command from the terminal:

composer require --dev "orchestra/canvas"

Usages

As a Laravel developer, you should be familiar with the following commands:

Which can be executed via:

php artisan make:migration CreatePostsTable --create

With Canvas, you can run the equivalent command via:

vendor/bin/canvas make:migration CreatePostsTable --create

canvas.yaml Preset file

To get started you can first create canvas.yaml in the root directory of your Laravel project or package.

Laravel preset

You can run the following command to create the file:

vendor/bin/canvas preset laravel

Which will output the following as canvas.yaml:

preset: laravel

namespace: App

model:
  namespace: App

Package preset

You can run the following command to create the file:

vendor/bin/canvas preset package

Which will output the following as canvas.yaml:

preset: package

namespace: PackageName
user-auth-provider: App\User

paths:
  src: src
  resource: resources

factory:
  path: database/factories

migration:
  path: database/migrations
  prefix: ''

console:
  namespace: PackageName\Console

model:
  namespace: PackageName

provider:
  namespace: PackageName

testing:
  namespace: PackageName\Tests

You need to change PackageName to the root namespace for your package.

Alternatively, you can set --namespace option to ensure the namespace is used in the file:

vendor/bin/canvas preset package --namespace="Foo\Bar"
preset: package

namespace: Foo\Bar
user-auth-provider: App\User

paths:
  src: src
  resource: resources

factory:
  path: database/factories

migration:
  path: database/migrations
  prefix: ''

console:
  namespace: Foo\Bar\Console

model:
  namespace: Foo\Bar
  
provider:
  namespace: Foo\Bar

testing:
  namespace: Foo\Bar\Tests

Integration with Laravel

By default, you can always use composer exec canvas for Laravel and Packages environment. However, with the Package Discovery Orchestra\Canvas\LaravelServiceProvider will be installed automatically and override all default make commands available via artisan so you can use it without changing anything.