Simple Comments Package for Laravel

Packages

June 28th, 2022

laravel-comments.png

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:

1use RyanChandler\Comments\Concerns\HasComments;
2 
3class Post extends Model
4{
5 use HasComments;
6}

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

1$post = Post::first();
2 
3$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:

1$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.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.

Laravel News Partners