24

Laravel Craftsman CLI

 6 years ago
source link: https://www.tuicool.com/articles/hit/Bfm6ZnA
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Laravel Craftsman is a CLI for easily crafting Laravel assets for any project (artisan make on steroids) by Mike Erickson . This project relies onLaravel 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


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK