Home / Snippets / How to make Livewire Component
How to make Livewire Component cover

How to make Livewire Component

461

3 years ago

0 comments

To create/make a Livewire component you can make use of the "livewire:make" command.

Make Livewire Command
To make a new component you can run the command below and replace the "<ComponentName>" with the component you want to create.
php artisan make:livewire <ComponentName>

Component Examples
Below are some of the components that you can come up with.
php artisan make:livewire PopularPosts
php artisan make:livewire ShowPosts
php artisan make:livewire AllComments
php artisan make:livewire LikeBox

Component Inside Sub-folder
If you plan to have the component inside a sub-folder then you can make use of "/" to separate it. 
php artisan make:livewire Post/Popular
php artisan make:livewire Post/Show
php artisan make:livewire Post/Likes

Livewire Inline Component
Sometimes you might need to create inline components which do not require separate views. To generate that you can pass on the "--inline" flag.
php artisan make:livewire PopularPosts --inline

The generate Livewire component should be as follows.
<?php
namespace App\Http\Livewire;

class PopularPosts extends Component
{
    public function render()
    {
        return <<<'blade'
            <div>Popular posts here</div>
        blade;
    }
}

Related Posts
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this