You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 3.x.

Making Components

Be amazing at Livewire
with our in-depth screencasts.
Watch Now

Introduction

Run the following artisan command to create a new Livewire component:

        
1php artisan make:livewire ShowPosts

Livewire also supports "kebab" notation for new components.

        
1php artisan make:livewire show-posts

Two new files were created in your project:

  • app/Http/Livewire/ShowPosts.php
  • resources/views/livewire/show-posts.blade.php

If you wish to create components within sub-folders, you can use the following different syntaxes:

        
1php artisan make:livewire Post\\Show
2php artisan make:livewire Post/Show
3php artisan make:livewire post.show

Now, the two created files will be in sub-folders:

  • app/Http/Livewire/Post/Show.php
  • resources/views/livewire/post/show.blade.php

Generating Tests

Optionally, you can include the --test flag when creating a component, and a test file will be created for you as well.

        
1php artisan make:livewire ShowPosts --test

Inline Components

If you wish to create Inline components (Components without .blade.php files), you can add the --inline flag to the command:

        
1php artisan make:livewire ShowPosts --inline

Now, only one file will be created:

  • app/Http/Livewire/ShowPosts.php

Here's what it would look like:

        
1class ShowPosts extends Component
2{
3 public function render()
4 {
5 return <<<'blade'
6 <div></div>
7 blade;
8 }
9}
← Previous Topic Installation
Next Topic → Rendering Components