Comment section with Laravel Livewire
Tech Stack: bootstrap-5, livewire
Demo
8 Comments
Code
Download
Usage
@livewire('comment', [
'model' => \App\Models\WinkPost::first(),
])
Documentation
This component uses a package named beyondcode/laravel-comments. Once the package is installed, you can prepare your models to accept comments.
Install package via Composer
composer require beyondcode/laravel-comments
The package will automatically register itself.
You can publish the migration with:
php artisan vendor:publish --provider="BeyondCode\Comments\CommentsServiceProvider" --tag="migrations"
After the migration has been published you can create the media table by running the migrations:
php artisan migrate
Prepare Models
This package uses the User Model
as the Author for the Comment, and stores the relationship in a user_id
column, if you want to use a different model, you can use this function instead and pass the model.
$post->commentAsUser($customUserModel,'comment content');
Next Up, Modify the model which can receive the comments as shown above in the Model Tab
That's it, now we can make comments to the WinkPost
Model, using the User Model
as the Author.
Tushar
16 minutes agoEdward Mulenga
16 minutes agoBreno Silva
16 minutes agoTushar
16 minutes agoMohammad
16 minutes agohadi
16 minutes ago