Making Components

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

Inline Components

If you wish to create Inline components (Component's 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