Extendable Interactive Make Command for Laravel

Overview

Extendable Interactive Make Command for Laravel

Make your life easier with interactive make command!

Installation

composer require hydreflab/laravel-make-me

Laravel >= 5.5

Package uses Laravel auto-discovery feature, so no service provider registration is needed.

Laravel <= 5.4

Manual service provider registration is required in config/app.php:

'providers' => [
    // ...
    
    HydrefLab\Laravel\Make\MakeServiceProvider::class,
]

Note: PHP >= 7.0 is required to run this package

Usage

To use interactive make, just run:

php artisan make

After that, you'll be asked what kind of class do you want to generate. Then, you'll be asked a series of questions in order to prepare class that suits your needs.

Interactive make integrates all default Laravel generator commands.

If you want to check what's available, simply run:

php artisan make --list

Why

Laravel's Artisan is a great tool. Laravel's generators (make) commands are great tools. Quite often they have a lot of additional options available. However, without checking out the command's code or run command with --help option, it is a mystery what additional stuff particular command can do. That's why I created this interactive make command. Enjoy!

[Edit]: I recently noticed that there is a similar package that also adds interactive make. Check that out, maybe it will suit you better.

Preview

Preview

Extendability

Quite often, as project advances, you end up in a situation that you're creating your own generator commands, your own make:something. It would be awesome if this new command could be included in the interactive make. Hey, that's possible.

To add custom (non-default) generator command to the interactive make:

  • command has to have public collectInputForInteractiveMake() method implemented,
  • collectInputForInteractiveMake method must return an array,
  • command must extend Illuminate\Console\Command class (since it is make-like command, I recommend to extend Illuminate\Console\GeneratorCommand),
  • command name must contain make: prefix, for example make:awesome.

Example:

<?php

class MyAwesomeMakeCommand extends \Illuminate\Console\Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'make:awesome';
    

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new awesome class';
    

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        // Generate something awesome
    }
    
    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return [
            ['name', InputArgument::REQUIRED, 'Your awesome name'],
        ];
    }
    
    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return [
            ['scale', 's', InputOption::VALUE_NONE, 'Awesomeness scale.'],
        ];
    }
    
    /**
     * Collect options for the interactive make command.
     * 
     * @return array
     */
    public function collectInputForInteractiveMake()
    {
        return [
            'name' => $this->ask('What is your name, awesome?'),
            '-s' => $this->ask('How awesome are you?', 10),
        ];
    }
}

That's it. MyAwesomeMakeCommand command will now be included in the interactive make as awesome.

You might also like...
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. 🚀

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

Twitter raffles in the command line, with PHP and minicli
Twitter raffles in the command line, with PHP and minicli

Rafflebird Rafflebird is a highly experimental CLI application for giveaways / raffles on Twitter, built in PHP with Minicli. Disclaimer: The recent s

A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

A PHP command line tool used to install shlink
A PHP command line tool used to install shlink

Shlink installer A PHP command line tool used to install shlink. Installation Install this tool using composer.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.
Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone. 🚀 Quick start Requires PHP 7.4+ # First, install: c

Vendor publish command for Lumen framework.

vendor:publish for Lumen framework This package contains a single command borrowed from the Laravel framework that enables you to use php artisan vend

Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt
Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt

EasyEngine v4 EasyEngine makes it greatly easy to manage nginx, a fast web-server software that consumes little memory when handling increasing volume

Generic PHP command line flags parse library
Generic PHP command line flags parse library

PHP Flag Generic PHP command line flags parse library Features Generic CLI options and arguments parser. Support set value data type(int,string,bool,a

Comments
  • Add '--force' option for commands

    Add '--force' option for commands

    Almost all commands are missing --force option. Laravel recently fixed --force flag usage, so we should handle this as well.

    Question is: add it to all input collectors or as a general flag for main make command?

    enhancement 
    opened by golonix 1
Releases(v1.0.0)
Owner
Hydref Lab
Hydref Lab
An Interactive Shell to Lumen Framework.

ABANDONED Please consider to use the official Laravel Tinker, it is also compatible with Lumen: laravel/tinker Lumen Artisan Tinker An Interactive She

Vagner Luz do Carmo 112 Aug 17, 2022
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

Yo-An Lin 428 Dec 13, 2022
Backup your laravel database by a simple artisan command

Backup your laravel database by a simple artisan command This package will allow you to backup your laravel app database and you can also choose to se

Mohammed Omer 23 Feb 10, 2022
Display your Laravel routes in the console, but make it pretty. 😎

Pretty Routes for Laravel Display your Laravel routes in the console, but make it pretty. ?? Installation You can install the package via composer: co

Alex 630 Dec 30, 2022
A package built for lumen that ports most of the make commands from laravel.

A package built for lumen that ports most of the make commands from laravel. For lumen v5.1, but will most likely work for 5.2 as well. I haven't tested. If you have requests, let me know, or do it yourself and make a pull request

Michael Bonds 22 Mar 8, 2022
Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

James Hall 745 Dec 30, 2022
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

null 324 Dec 8, 2022
Command-Line Interface tools

Aura.Cli Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and a

Aura for PHP 102 Dec 31, 2022
Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

Christoph Hochstrasser 18 Nov 1, 2019
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, instal

Nuno Maduro 11 Jun 10, 2021