Making Components
Run the following artisan command to create a new Livewire component:
php artisan make:livewire ShowPosts
Livewire also supports "kebab" notation for new components.
php 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:
php artisan make:livewire Post\\Show
php artisan make:livewire Post/Show
php 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:
php artisan make:livewire ShowPosts --inline
Now, only one file will be created:
app/Http/Livewire/ShowPosts.php
Here's what it would look like:
class ShowPosts extends Component
{
public function render()
{
return <<<'blade'
<div></div>
blade;
}
}
← Previous Topic
Installation
Next Topic →