Making Components

The make Command

It is highly recommended that you use the php artisan make:livewire command for all new components.

Here are a few examples of usage:

php artisan make:livewire foo
# Creates Foo.php & foo.blade.php

php artisan make:livewire foo-bar
# Creates FooBar.php & foo-bar.blade.php

php artisan make:livewire foo.bar
# Creates Foo/Bar.php & foo/bar.blade.php

php artisan make:livewire foo --inline
# Creates only Foo/Bar.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.

@livewire('foo')
@livewire('foo-bar')
@livewire('foo.bar')
@livewire(Package\Livewire\Foo::class)

If you are on Laravel 7 or greater, you can use the tag syntax.

<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.

php 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:

php artisan livewire:move foo bar.baz
# Foo.php|foo.blade.php -> Bar/Baz.php|bar/baz.blade.php
For convenience, 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:

php artisan livewire:copy foo bar
# Copies Foo.php & foo.blade.php to Bar.php and bar.blade.php

php artisan livewire:copy foo bar --force
# Overwrites existing "bar" component
For convenience, 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:

php artisan livewire:delete foo
# Removes Foo.php & foo.blade.php

php artisan livewire:delete foo --force
# Removes without confirmation prompt
For convenience, livewire:delete is aliased to livewire:rm
← Previous Topic

Installation

Next Topic →

The render() Method

Laravel Intellow Cierra 1043 Labs JR Merritt Trustfactory