Laravel Craftsman CLI

Laravel Craftsman CLI

Laravel Craftsman is a CLI for easily crafting Laravel assets for any project (artisan make on steroids) by Mike Erickson. This project relies on Laravel Zero, providing a suite of “project agnostic” CLI tools that you install globally:

composer global require codedungeon/laravel-craftsman

You can create all assets for a typical model/view/controller setup using the craft:all command:

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

Take note that this command also takes care of extending the layouts/app.blade.php file in template files.

Here’s an example from the readme you can use to generate a migration file complete with the table definition using the --fields option:

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

# results in...
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');
});

The project also allows you to configure the templates used for the generated files with the Mustache templating language. Here’s an example of the class template at the time of writing:

<?php

namespace {{namespace}};

class {{model}}
{
    {{#constructor}}
    function __construct() {}
    {{/constructor}}
}

Check out the readme for the full list of commands and flags. You can also run laravel-craftsman list from the command line after you’ve installed the package globally and added it to your path. You can learn more about this package and check out the source code on GitHub at mikeerickson/laravel-craftsman.


Filed in: News / Artisan


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Engineer
Remote okay (must already live in USA)
Hawthorne Effect
Senior Software Engineer (Remote - Contract)
Remote
Koodi Systems
PHP Developer
Pittsburgh / Remote
Sequoia Waste Solutions
Software Developer
Eindhoven
Simac IDS
Application Developer Level II (CakePHP / MySql / Vue.js)
Lancaster, PA
Harbor Compliance
FULL STACK LARAVEL DEVELOPER
LONDON - WEST END
AMPERSAND HEATLH
Mid/Senior Laravel Developer - U.S. Developers Only
Kenner, Louisiana
Profit Miner Technologies