Skyrocketing your speed with Laravel — Photo by SpaceX

Create make:custom commands in Laravel 5.7+

Felix Ayala
1 min readSep 14, 2018

--

Introduction

Laravel provides a number of helpful make commands that allows you to create template files in order to speed up your development process. You can explore it with php artisan make

In a recent project, I had needed to create many Interfaces but in the Artisan make command list there was no option to build an Interface or a Contract stub so I decided to create a custom one which adds the make:contract command.

Building our Command

First we need to create a dummy stub, create a file named make-contract.stub, this file will be placed in the directory app/Console/Commands/Stubs/make-contract.stub with the following content:

You can add more method signatures according to your needs.

Next create a command class with php artisan make:command MakeContract , this file will be in app/Console/Commands directory. Replace the contents with this:

Usage

Let’s create a simple Contract in the command line:

$ php artisan make:contract Billable

It will be interesting create a command that allow us to generate any kind of artisan make:custom commands but this is ok for now.

I hope that you enjoyed this article. Thanks for reading.

--

--