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

Software Engineer Lead (PHP)
Remote
CivicPlus, LLC
Full-time Senior Web Developer
Detroit, MI
Wayne State University
Senior Software Engineer
Sydney, Australia
FoodByUs
Full Stack Engineer
Remote or Medford, Oregon
Empire Medical
Laravel Developer (fulltime - Dutch only)
Netherlands
Qbixx | Webservices
Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Remote
Bisnow Media