Laravel 7: Customize stubs

Zubair Mohsin - Feb 28 '20 - - Dev Community

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.

stubs-directory

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
{
    //
}
Enter fullscreen mode Exit fullscreen mode

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()
    {

    }
}
Enter fullscreen mode Exit fullscreen mode

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()
    {

    }
}
Enter fullscreen mode Exit fullscreen mode

Happy Stubbing 👨🏽‍💻☝🏽

Let me know in comments how this can help you 🤓

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player