I am trying to use this package in livewire For like a post,
I am very interested in using livewire,But I am new to use livewire, I do not know how to do this,
Can you give me an example of a livewire component?
please guide me
How to Use like package in livewire
Hey, @shadi
Using livewire component it’s like using laravel controllers, except livewire calls the component via ajax request.
So, for example. you want to use the liker package. Do the following:
Create livewire component
php artisan make:livewire user.user-like
Inside user/user-like.blade.php
Call Method from the component
<button wire:click="like({{ $page->id }})">Like me</button>
inside UserLike
component
public function like($pageId)
{
$user = auth()->user();
$page = Page::where('id', $pageId)->first();
$user->like($page);
// return flash message or redirect the user ...
}
This is the basic of livewire and to learn more please read the documentation or watch the screencases
1 Like