Artisan Commands
The make
command
1php artisan make:livewire foo 2# Creates Foo.php & foo.blade.php 3 4php artisan make:livewire foo-bar 5# Creates FooBar.php & foo-bar.blade.php 6 7php artisan make:livewire foo.bar 8# Creates Foo/Bar.php & foo/bar.blade.php 9 10php artisan make:livewire foo --inline11# Creates only Foo.php
Once created, you can render your components in a Blade file with the @livewire('component-name')
blade directive.
Think of Livewire components like Blade includes. You can insert @livewire
anywhere in a Blade view and it will render.
1@livewire('foo')2@livewire('foo-bar')3@livewire('foo.bar')4@livewire(Package\Livewire\Foo::class)
If you are on Laravel 7 or greater, you can use the tag syntax.
1<livewire:foo />
Modifying Stubs
You can customize the stubs (templates) that Livewire uses to create new component classes and views using the livewire:stubs
command.
1php artisan livewire:stubs
The above command will create three files:
stubs/livewire.stub
stubs/livewire.view.stub
stubs/livewire.inline.stub
Now, when you run the make:livewire
command, Livewire will use the above stub files as the template.
The move
Command
The php artisan livewire:move
command will move/rename the component class and blade view, taking care of namespaces and paths
Here is an example of usage:
1php artisan livewire:move foo bar.baz2# Foo.php|foo.blade.php -> Bar/Baz.php|bar/baz.blade.php
livewire:move
is aliased to livewire:mv
The copy
Command
The php artisan livewire:copy
command will create copies of the component class and blade view, taking care of namespaces and paths
Here are a few examples of usage:
1php artisan livewire:copy foo bar2# Copies Foo.php & foo.blade.php to Bar.php and bar.blade.php3 4php artisan livewire:copy foo bar --force5# Overwrites existing "bar" component
livewire:copy
is aliased to livewire:cp
The delete
Command
The php artisan livewire:delete
command will remove the component class and blade view.
Here are a few examples of usage:
1php artisan livewire:delete foo2# Removes Foo.php & foo.blade.php3 4php artisan livewire:delete foo --force5# Removes without confirmation prompt
livewire:delete
is aliased to livewire:rm