Back to Course |
Livewire 3 From Scratch: Practical Course

Quick Tip: Customizing Default Stubs

Similar to how you can publish stubs with Laravel, you can do that for Livewire.

php artisan livewire:stubs

This command will create four new files in the stubs directory:

  • stubs/livewire.stub
  • stubs/livewire.inline.stub
  • stubs/livewire.test.stub
  • stubs/livewire.view.stub

For example, when you create a new Livewire component and always want to have a mount method and type hint all the methods, you need to modify stubs/livewire.stub file.

<?php
 
namespace [namespace];
 
use Livewire\Component;
use Illuminate\Contracts\View\View;
 
class [class] extends Component
{
public function mount(): void
{
 
}
 
public function render(): View
{
return view('[view]');
}
}

Now when you will create a new Livewire component

php artisan make:livewire CreateProject

The PHP class for the CreateProject component would look like this:

use Livewire\Component;
use Illuminate\Contracts\View\View;
 
class CreateProject extends Component
{
public function mount(): void
{
 
}
 
public function render(): View
{
return view('livewire.create-project');
}
}