Laravel Packages

Simple Comments Package for Laravel

Published
Simple Comments Package for Laravel image

The Laravel Comments package by Ryan Chandler is a dead-simple package for adding comments to models in Laravel. Using the HasComments trait on your models, you can quickly add comments attributed to users:

use RyanChandler\Comments\Concerns\HasComments;
 
class Post extends Model
{
use HasComments;
}

Given a post model, you can add a comment using the following method:

$post = Post::first();
 
$post->comment('Hello, world!');

The above example is automatically attributed to the logged-in user. You can also assign a comment to a specific user:

$post->comment('Hello, world!', user: $user);

This package also supports comment parent threads, meaning a comment can belong to another comment.

You can learn about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article