Customize Laravel Stubs and save a lot of time

victoor

Víctor Falcón

Posted on April 22, 2021

Customize Laravel Stubs and save a lot of time

Did you know that it's possible to customize Laravel stubs, so you can make a new controller, and it will be created in your own way?

Video in Spanish 🇪🇸

Publish and customize your stubs

The first thing that you have to do to customize your stubs it's publishing the default templates that comes with Laravel. You just need to run this artisan command:

artisan stub:publish
Enter fullscreen mode Exit fullscreen mode

This will generate a new folder in resoureces/stubs with all the default templates.

In that folder you can change any of them and it will be used every time you run an artisan make command of any kind.

How to create your own crontollers?

With each file type we have only one option, buy with controller we can create as much as we want. As you can see we can find a lot of controller.{type}.php files in the stub folder. We can customize each of them or create new ones.

For example, if we create a controller.custom.php then we can use this stub with:

artisan make:controller  UserController --type=custom
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
victoor
Víctor Falcón

Posted on April 22, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related