PHPackages                             codedungeon/laravel-craftsman - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. codedungeon/laravel-craftsman

ActiveProject[Framework](/categories/framework)

codedungeon/laravel-craftsman
=============================

Laravel Craftsman

1.12.0(5y ago)2323278[2 issues](https://github.com/mikeerickson/laravel-craftsman/issues)MITPHPPHP ^7.1.3CI failing

Since Mar 29Pushed 5y ago6 watchersCompare

[ Source](https://github.com/mikeerickson/laravel-craftsman)[ Packagist](https://packagist.org/packages/codedungeon/laravel-craftsman)[ Docs](https://laravel-craftsman.com)[ RSS](/packages/codedungeon-laravel-craftsman/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (12)Versions (46)Used By (0)

Laravel Craftsman
=================

[](#laravel-craftsman)

Description
-----------

[](#description)

Laravel Craftsman (written using the awesome [Laravel-Zero](https://www.laravel-zero.com) CLI builder) provides a suite of crafting assets using a project agnostic CLI.

You can quickly create `class`, `command`, `controller`, `event`, `factory`, `form-request`, `listener`, `migration`, `model`, `resource`, `rule`, `seed`, `test` and `view` assets.

In addition, you can create all assets with a single command, allowing you to quickly craft a new resource in seconds!

📝 [Laravel News Article](https://laravel-news.com/laravel-craftsman-cli)

📦 [Packagist](https://packagist.org/packages/codedungeon/laravel-craftsman)

 [![Laravel Craftsman](docs/images/laravel-craftsman.png)](docs/images/laravel-craftsman.png)
=============================================================================================

[](#----)

Table Of Conents
----------------

[](#table-of-conents)

- [Installation](#installation)
- [Usage](#usage)
- [Commands](#commands)
- [Tips](#tips)
- [Custom Templates](#custom-templates)
- [License](#license)
- [Credits](#credits)

Installation
------------

[](#installation)

### Using Composer

[](#using-composer)

```
> composer global require codedungeon/laravel-craftsman
```

### Using curl/wget

[](#using-curlwget)

```
> curl -o laravel-craftsman https://github.com/mikeerickson/laravel-craftsman/archive/master.zip

or

> wget https://github.com/mikeerickson/laravel-craftsman/archive/master.zip
```

Usage
-----

[](#usage)

```
> laravel-craftsman  [options] [arguments]

> laravel-craftsman interactive
> laravel-craftsman interactive --silent

> laravel-craftsman publish
> laravel-craftsman publish --overwrite

> laravel-craftsman craft:all Post --model App/Models/Post --tablename posts --rows 50 --extends layouts.app --section content

> laravel-craftsman craft:api --model App/TestClass --overwrite

> laravel-craftsman craft:class App/TestClass --constructor

> laravel-craftsman craft:controller PostController --model App/Models/Post

> laravel-craftsman craft:event ContactCreated
> laravel-craftsman craft:event ContactCreated --no-broadcast

> laravel-craftsman craft:factory PostFactory --model App/Models/Post

> laravel-craftsman craft:migration create_posts_table --table posts

> laravel-craftsman craft:model App/Models/Post --table posts
> laravel-craftsman craft:model App/Models/Post --table posts --migration

> laravel-craftsman craft:request CustomerRequest --rules "title?required|unique|posts,body?required"

> laravel-craftsman craft:rule Uppercase

> laravel-craftsman craft:seed PostTableSeeder --model App/Models/Post --rows 100

> laravel-craftsman craft:views authors --extends partials.master --section content
```

Commands
--------

[](#commands)

The following commands are available in any Laravel project. You can use the individual crafting routines which are similar to the Artisan commands, but the `craft:all` command is the most powerful of the bunch.

Using `craft:all` you can easily generate all assets (controller, factory, migration, model, and seed) for a given resource (ie Post, Customer, etc)

```
laravel-craftsman craft:all Contact \
  --model App/Models/Contact \
  --tablename contacts \
  --rows 50 \
  --fields "first_name:string@30:nullable,last_name:string@50:nullable,email:string@80:nullable:unique"
```

🚩Required Parameter / Option

CommandName / OptionDescription**interactive****Run Interactive Mode (uses wizard to craft resources**--silent, -sSkips Wizard Instructions**publish****Publish templates to project diretory***==&gt; all craft:xxx commands will use project template if it exists*--skip-config, -cSkip publishing craftsman configuration file--overwrite, -oOverwrites published templates directory**craft:api****Craft API Resources (create model, controller, factory, migration, seed)****🚩 base name**Based resource name for all assets (example Contact)**🚩 --model, -m**Path to model (eg App/Models/Post)--table, -tTablename used in database (will set $tablename in Model)*If not supplied, default table will be pluralized model name*--rows, -rNumber of rows used by seed when using Factory--current, -uUse --useCurrent for timestamps when creating migration--no-model, -oDo not create model--no-controller, -cDo not create controller--no-factory, -fDo not create factory--no-migration, -gDo not create migration--no-seed, -sDo not create seed--overwrite, -wOverwrite existing class**craft:all****Creates all assets (Controller, Factory, Migration, Model, Seed)****🚩 base name**Based resource name for all assets**🚩 --model, -m**Path to model (eg App/Models/Post)--tablename, -tTablename used in database (will set $tablename in Model)*If not supplied, default table will be pluralized model name*--rows, -rNumber of rows used by seed when using Factory--extends, -xView extends block (optional)--section, -iView section block (optional)--no-controller, -cDo not create controller--no-factory, -aDo not create factory--no-migration, -gDo not create migration--no-model, -oDo not create model--no-seed, -sDo not create seed--no-views, -eDo not create seed**craft:class****Creates empty class****🚩 class name**Class path (eg App/Services/MyService)--constructor, -cInclude constructor method--template, -tPath to custom template (override config file)--overwrite, -wOverwrite existing class**craft:command****Creates Artisan Command class****🚩 command name**Command name--signature, -sCommand Signature--description, -dCommand Description--template, -tPath to custom template (override config file)--overwrite, -wOverwrite existing class**craft:controller****Create controller using supplied options****🚩 controller name**Controller Name--model, -mPath to model (eg App/Models/Post)--validation, -lCreate validation blocks where appropriate--api, -aCreate API controller (skips create and update methods)--binding, -bInclude route / model binding (requires model property)--empty, -eCreate empty controller--resource, -rCreate resource controller--template, -tPath to custom template (override config file)--overwrite, -wOverwrite existing class**craft:event****Creates event class****🚩 event name**Event Name--listener, -lGenerate Listener--no-broadcast, -bSkips broadcast code when event class created--template, -tPath to custom template (override config file)--overwrite, -wOverwrite existing class**craft:factory****Creates factory using supplied options****🚩 factory name**Factory Name--model, -mPath to model (eg App/Models/Post)**craft:listener****Creates listener class****🚩 listener name**Listener Name--event, -eThe event class be listener for--queuedIndicates the event listener should be queued--template, -tPath to custom template (override config file)--overwrite, -wOverwrite existing class**craft:migration****Creates migration using supplied options****🚩 migration name**Migration Name (eg create\*contacts\_table)**--model, -m**Path to model (required)--table, -tTablename used in database (will set $tablename in Model)\_If not supplied, default table will be pluralized model name\*--fields, -fList of fields (option) *see syntax below***🚨 If you have spaces separating fields, you must surround fields list in quotes**--foreign, -rAdd foreign key constraint (foreign info) *see syntax below*--current, -uUse --useCurrent for timestamps (skipped by default)--down, -dInclude down methods (skipped by default)--template, -tPath to custom template (override config file)--overwrite, -wOverwrite existing class**craft:model****Creates model using supplied options****🚩 model name**Model Name (eg Contact or App/Models/Contact)*See below about defining alternate model path*--all, -aGenerate a migration, factory, and controller for the model--table, -tTablename used in database (will set $tablename in Model)*If not supplied, default table will be pluralized model name*--template, -mPath to custom template (override config file)--controller, -cCreate a new controller--factory, -fCreate factory--migration, -mCreate a new migration file file--seed, -sCreate a new seed file file--overwrite, -wOverwrite existing class**craft:request****Creates form request using supplied options****🚩 request name**Request Name*See below about defining alternate model path*--rules, -rList of rules (optional)**🚨 If you have spaces separating fields, you must surround rules lists in quotes**--template, -mPath to custom template (override config file)--overwrite, -wOverwrite existing class| **craft:rule** | | **Creates validation rule** | | | **🚩 Rule Name** | Rule Name (eg Uppercase) | | | --template, -t | Path to custom template (override config file) | | | --overwrite, -w | Overwrite existing class | | **craft:seed** | | **Creates seed file using supplied options** | | | **🚩 Seed Name** | Seed Name (eg ContactTableSeeder) | | | **🚩 --model, -m** | Path to model (eg App/Models/Post) | | | --factory, -f | Create Factory (if it does not already exists) | | | --rows, -r | Number of rows to use in factory call (Optional) | | | --template, -t | Path to custom template (override config file) | | | --overwrite, -w | Overwrite existing class | | **craft:test** | | **Creates seed file using supplied options** | | | **🚩 Test Name** | Test Name (eg CreateFileTest) | | | --setup, -s | Include setUp method | | | --teardown, -d | Include tearDown method | | | --unit, -u | Create unit test (default will be Feature test) | | | --pest, -p | Create Pest test | | | --template, -t | Path to custom template (override config file) | | | --overwrite, -w | Overwrite existing class | | **craft:views** | **🚩 base resource** | **Seed name** | | | --setup, -s | Include setup block | | | --teardown, -d | Include tearDown block | | | --unit, -u | Create unit test | | | --template, -t | Path to custom template (override config file) | | | --overwrite, -w | Overwrite existing class | | **craft:views** | **🚩 base resource** | **Creates view files** | | | --extends, -x | Includes extends block using supplied layout | | | --section, -s | Includes section block using supplied name | | | --no-create, -c | Exclude create view | | | --no-edit, -d | Exclude edit view | | | --no-index, -i | Exclude index view | | | --no-show, -w | Exclude show view |

### Defining Class Path

[](#defining-class-path)

When crafting resources which are not automatically created in their assigned directories, you can define the location to the path where asset is created as follows:

```
> laravel-craftsman craft:class App/Services/Sync ...
```

This will create a class in the `App/Services` path, with filename `Sync.php`. Directories (including nested directories) will be created if they do not already exists.

#### Supported Commands

[](#supported-commands)

The following commands support defining class path

- craft:class
- craft:event
- craft:factory
- craft:listener
- craft:model
- craft:seed
- craft:test
- craft:views

### 📝 Template Access

[](#-template-access)

Laravel Craftsman will use sensible default templates which are located in the `laravel-craftsman` installation location. If you wish to have greater control over templates, you can publish (see `laravel-craftsman publish` command) default templates into the project directory (`/templates`).

Subsequent `laravel-craftsman craft:xxx` commands will first look in the project templates directory, if template not found, then it will use the application templates.

#### Single Use Templates

[](#single-use-templates)

In addition to the standard templates, you may also define a single use template which is only used during command execution. Single use templates are designed to reference project specific templates, and you use the `` keyword when executing the desire command.

```
> laravel-craftsman craft:class App/Services/SyncService --template "/templates/service.mustache" ...
```

### oh-my-zsh Conflict

[](#oh-my-zsh-conflict)

If you have `oh-my-zsh` installed, make sure you wrap template value in quotes, otherwise you may receive an error

```
laravel-craftsman craft:class TestService --template /templates/custom.mustache --overwrite
zsh: no such file or directory: project
```

### Foreign Key Syntax

[](#foreign-key-syntax)

When using the `--foreign` option when building migrations, you should use the following syntax:

```
format:
foreignKey:primaryId,primaryTable

example:
--foreign=post_id:id,posts
-r=post_id:id,posts
```

Alternatively, you can supply just the foreign key part (using table\_key format) and it will be used to extract the primary table and key. The primary table will be a plural version of the first part, followed by the primary key id.

```
--foreign=post_id
```

will be translated internally to use the full `--foreign` format

```
--foreign=post_id:id,posts
```

#### Automatic foreign key field creation

[](#automatic-foreign-key-field-creation)

When using the `--foreign` flag, the appropriate field will be added automatically in migration file. For example, if the `--foreign post_id` flag is supplied, the following will be added to new migration

```
    ...
    Schema::create('comments', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedBigInteger('post_id');
        ...
        $table->foreign('post_id')->references('id')->on('posts');
    });
    ...
```

### Field Option Syntax

[](#field-option-syntax)

When using the `--fields` option when building migrations, you should use the following syntax: Note: If you have used teh `--foreign` flag as outlined above, the foreign key field will be added automatically

```
format:
fieldName:fieldType@fieldSize:option1:option2:option3

example:
email:string@80:nullable:unique

--fields "fname:string@25:nullable,lname:string@50:nullable,email:string@80:nullable:unique,dob:datetime,notes:text,deleted_at:timezone"

    Schema::create('contacts', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->timestamps();
        $table->string('fname', 25)->nullable();
        $table->string('lname', 50)->nullable();
        $table->string('email', 80)->nullable()->unique();
        $table->datetime('dob');
        $table->text('notes');
        $table->timezone('deleted_at');
    });
```

### Rules Option Syntax

[](#rules-option-syntax)

When using the `--rules` option when building form requests, you should use the following syntax:

```
format:
ruleName?rule1|rule2|rule3,ruleName2?rule1|rule2
```

```
> laravel-craftsman craft:request CustomerRequest --rules "title?required|unique|posts,body?required"
```

Produces the following

```
public function rules()
{
    return [
        "title" => "required|unique|posts",
        "body" => "required",
    ];
}
```

Tips
----

[](#tips)

💡 **Boolean Option Shortcut**

When executing any of the `laravel-craftsman` commands, if you wish to apply one or more switches (those options which do not require a corresponding value), you can use the standard CLI shorthands (this tip can be used in any CLI based tool, not just `laravel-craftsman` (well assuming the CLI actually supports shorthand).

For example:

Lets assume you wish to wish to create `views`, you can use the following command to skip creation of the create (-c), edit (-d) and show (-w) views (only creating the index view). The combination of `-cdw` is shorthand for `--no-create --no-edit --no-show`

```
> laravel-craftsman craft:views --extends layouts.app --section content -cdw
```

is same as

```
> laravel-craftsman craft:views --extends layouts.app --section content --no-create --no-edit --no-show

> laravel-craftsman craft:views --extends layouts.app --section content -c -d -w
```

💡 **Defining Nested Paths**

Any command can store assets within tested folders within default path by separating `name` argument with forward slash For example, the following command will define the path for model asset in the `App/Models/` path

```
> laravel-craftsman App/Models/Customer ...
```

Custom Templates
----------------

[](#custom-templates)

Laravel Craftsman provides support for creating custom templates if you wish to change the syntax to match your personal style. The default templates use the standard Laravel syntax, but we like to allow ou have your own flair (see `laravel-craftsman publish` for greater template control).

📝 **User Custom Templates**

If you wish to create derivatives of the supported templates, you can customize the `config.php` located in the `laravel-craftsman` directory. By default, this will be `~/.composer/vendor/codedungeon/laravel-craftsman`, but may be different depending on the method you chose to install laravel-craftsman.

```
    'templates' => [
            'class' => 'user_templates/class.mustache',
            'api-controller' => 'user_templates/api-controller.mustache',
            'binding-controller' => 'user_templates/binding-controller.mustache',
            'empty-controller' => 'user_templates/empty-controller.mustache',
            'command' => 'user_templates/command.mustache',
            'controller' => 'user_templates/controller.mustache',
            'events' => 'user_templates/event.mustache',
            'factory' => 'user_templates/factory.mustache',
            'listener' => 'user_templates/listener.mustache',
            'migration' => 'user_templates/migration.mustache',
            'model' => 'user_templates/model.mustache',
            'request' => 'user_templates/request.mustache',
            'rule' => 'user_templates/rule.mustache',
            'seed' => 'user_templates/seed.mustache',
            'test' => 'user_templates/tested.mustache',
            'view-create' => 'user_templates/view-create.mustache',
            'view-edit' => 'user_templates/view-edit.mustache',
            'view-index' => 'user_templates/view-index.mustache',
            'view-show' => 'user_templates/view-show.mustache',
        ],
```

📝 **Single Use Template**

In addition to creating templates and configuring the `config.php` file, you may optionally supply a template to be used as single use (not stored) from all command execution For example, if you wish to create a standard class asset, you can use a single use template as follows:

 Placeholder to represent current project directory ./ Placeholder to represent current project directory Placeholder to computer root directory

```
> laravel-craftsman craft:class App/Services/Syncronize --template "/templates/service.mustache"

> laravel-craftsman craft:class App/Services/Syncronize --template "./templates/model.mustache"

> laravel-craftsman craft:class App/Services/Syncronize --template "/templates/model.mustache"
```

📝 **Template Variables**

The following variables can be used in any of the supported templates (review the `templates` directory for a basis of how to create custom templates)

Variable NameTemplates which variable is used`binding`Used by `binding controller``fields`Used by `migration``model`Used by `api-controller`, `class`, `controller`, `factory`, `migration`, `model` and `seed``model_path`Used by `api-controller`, `controller`, `factory`, `migration`, `seed``name`Used by `event`, `listener`, `rule`, `api-controller`, `controller` and `empty-controller``namespace`Used by `class`, `model``num_rows`Used by `seed``rules`Used by `request``tablename`Used by `controller`, `migration`, `model``extends`Used by `views``section`Used by `views``foreign`Used by `migration``current`Used by `migration`License
-------

[](#license)

Copyright © 2019-2020 Mike Erickson Released under the MIT license

Credits
-------

[](#credits)

laravel-craftsman written by Mike Erickson

E-Mail:

Twitter: [@codedungeon](http://twitter.com/codedungeon)

Website: [codedungeon.io](http://codedungeon.io)

###  Health Score

36

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Recently: every ~54 days

Total

36

Last Release

2008d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f90b03078e9f9d22696c61f21aa3b07b68dfeff1a683fefe1f5403018a3c1671?d=identicon)[codedungeon](/maintainers/codedungeon)

---

Top Contributors

[![mikeerickson](https://avatars.githubusercontent.com/u/183153?v=4)](https://github.com/mikeerickson "mikeerickson (150 commits)")

---

Tags

artisancraftcraftsmangeneratorhacktoberfesthacktoberfest2020laravelphpunitcliconsoleframeworkpestlaravelgeneratorscaffoldartisanlaravel-zeromake

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/codedungeon-laravel-craftsman/health.svg)

```
[![Health](https://phpackages.com/badges/codedungeon-laravel-craftsman/health.svg)](https://phpackages.com/packages/codedungeon-laravel-craftsman)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
