In Laravel 7, you will be able to customize stubs.
Publishing stubs
In order to customize stub files, you need to publish them:
php artisan stub:publish
After running this command, a new directory will be added in your project.
Let's have a look at most commonly used php artisan make:controller
command stub file controller.plain.stub
<?php
namespace {{ namespace }};
use {{ rootNamespace }}Http\Controllers\Controller;
use Illuminate\Http\Request;
class {{ class }} extends Controller
{
//
}
You can make any kind of changes to this stub file.
Example
Let's say we want every controller to have an __invoke()
function.
<?php
namespace {{ namespace }};
use {{ rootNamespace }}Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Foundation\Inspiring;
class {{ class }} extends Controller
{
public function __invoke()
{
}
}
Now let's make a controller:
php artisan make:controller StubsTestController
Output:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class StubsTestController extends Controller
{
public function __invoke()
{
}
}
Happy Stubbing 👨🏽💻☝🏽
Let me know in comments how this can help you 🤓