Comment section with Laravel Livewire

Tech Stack: bootstrap-5, livewire

Demo

8 Comments

Tushar
50 minutes ago
Very straight-to-point article. Really worth time reading. Thank you! But tools are just the instruments for the UX designers. The knowledge of the design tools are as important as the creation of the design strategy.
Edward Mulenga
50 minutes ago
Hope you are doing well.
Breno Silva
50 minutes ago
TALL Stack is so cool.
Tushar
50 minutes ago
This comment component is built using Livewire/Alpine and Tailwind CSS.
Mohammad
50 minutes ago
This is a comment.
hadi
50 minutes ago
This is a another comment.

Code
Download

Sorry, this component's code is restricted
Get Livewiredemos-Pro
Sorry, this component's code is restricted
Get Livewiredemos-Pro
Sorry, this component's code is restricted
Get Livewiredemos-Pro

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.