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 8# Creates Foo.php & foo.blade.php 9 10php artisan make:livewire FooBar11# Creates FooBar.php & foo-bar.blade.php12 13php artisan make:livewire foo.bar14# Creates Foo/Bar.php & foo/bar.blade.php15 16php artisan make:livewire foo --inline17# Creates only Foo.php18 19php artisan make:livewire foo --test20# Creates Foo.php, foo.blade.php, & FooTest.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, blade view and the component test if it exists, taking care of namespaces and paths
Here is an example of usage:
1php artisan livewire:move foo bar.baz2# Foo.php|foo.blade.php|FooTest.php -> Bar/Baz.php|bar/baz.blade.php|Bar/BazTest.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" component6 7php artisan livewire:copy foo bar --test8# Copies Foo.php & foo.blade.php & FooTest.php to Bar.php & bar.blade.php & BarTest.php
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 prompt6 7php artisan livewire:delete foo --test8# Removes Foo.php & foo.blade.php & FooTest.php
livewire:delete
is aliased to livewire:rm