Laravel: How to Create Custom Artisan Command

By | August 16, 2016

There’s only 3 steps required to setting up new Artisan command.

  1. Step 1 – Create a new console file
php artisan make:console CommandName
  1. Step 2 – Open up app/Console/Commands/CommandName.php and update the signature and the description property.
     /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'env:db';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Configure database settings';
  1. Step 3 – Register your new Artisan command in app/Console/Kernel.php
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // CommandsInspire::class,
        CommandsDatabaseEnvironment::class
    ];

Now you’re ready with your new artisan command. Check your command with php artisan. It should have something like this one.

Screen Shot 2016-08-16 at 6.05.26 PM

Here the a sample code.

Reference

Artisan

Leave a Reply

Your email address will not be published. Required fields are marked *

17 − three =