Download the PHP package melsaka/commentable without Composer

On this page you can find all versions of the php package melsaka/commentable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package commentable

Commentable

The Commentable package for Laravel provides a convenient way to manage comments and comment-related functionality in your application. This documentation will guide you through the usage of this package.

Table of Contents

Installation

Add the package to your Laravel app via Composer:

Register the package's service provider in config/app.php.

Run the migrations to add the required table to your database:

Add CanComment trait to the comment owner model, User model for example:

Add HasComments trait to your commentable model, Post model for example:

If you want to enable rating feature in any commentable model (Post model in this case) add commentsAreRated() method.

By default, comments are not rated false. You can change this by adding this method and making it return true.

By default, new comments are accepted, but sometimes you don't want to approve comments for all users;

In this case add commentsAreAccepted() method and make it return false, it return true by default.

The owner model that uses the CanComment trait also has a commentsAreAccepted() method, which returns false by default.

You can make this method return true for admin users only for emaple, so all admin users comments be accepted automatically.

Configuration

To configure the package, publish its configuration file:

You can then modify the configuration file to change the comments table name if you want, default: comments.

Usage

Adding Comments

To add a new comment, you can use the add method after for and via methods like this:

Note: We may use $post, $owner, $parent variables in the upcoming examples.

You can also add comments in a many different ways:

Note: all these methods accept $parent param but it's null by default. so you can do this as well:

Editing Comments

To edit a comment, use the edit method and pass the $comment you want to edit as the first parameter:

You can also edit comments using different methods:

In this example: $comment->for($post)->editTo($data);, The for method reduces the queries executed.

But you can edit comments without it since we fetch the commentable model anyway, if you don't provide it in a for method.

Also the editComment method won't update, if comment commentable_id or owner_id is not the same as $post->id or $owner->id.

Note: all these methods accept $parent param but it's null by default. so you can do this as well:

You can also add a parent to a comment using addParent() method

Removing Comments

To remove one or more comments, use the remove method:

To remove a single comment instance, you can also use:

You can remove comments in different ways:

The deleteComment and removeComment methods won't remove $comment, if comment commentable_id or owner_id is not the same as $post->id or $owner->id.

Changing Comment Status

You can change the comment status to accepted using the accept method:

To reject a comment, use the reject method:

You can also accept or reject comments on a post:

The acceptComment and rejectComment methods won't update $comment status, if comment commentable_id or owner_id is not the same as $post->id or $owner->id.

Rating Comments

To change the rating of a comment, use the rateIt method:

You can also rate a comment using these methods:

rateComment returns false if $post commentsAreRated is false or commentable_id is not the same as $post->id.

You can also get the post average rate using averageRate() method.

Getters Methods

To get comment by id, you can use Comment::getCommentOfId($id) it returns 404 if id not exist.

Note: if you give it a valid $comment instance it will return it back to you.

You can also use various getter methods to retrieve comments:

Get Post Comments

Get User Comments

Get Post Comments by User

Eager Load Comment Replies and Replies Count

Get Only Accepted Replies

Get Only Rejected Replies

These methods can also accept callback functions for further customization.

You can use callback function within the with, withCount, load and loadCount methods:

You can also use with and load methods from commentable and owner models like this:

These methods accept callback function as well.

You can also load replies/repliesCount.

And all of them accept a callback function:

Relation Methods

Comment Model has this relation setup that you may need to use in your app:

You can get the comments from related model like this:

Every related model CanComment or HasComments have these built-in methods as well:

You can use the morphsArray() method to filter by commentable or owner like this:

But the difference is that (of, by) methods return onlyParent comments withRepliesCount.

While this code:

Returns comments and replies toghter without reply count and you will have to check the parent_id to know which is the parent comment and which is the reply.

Filters

If you want to filter the comments you can use these methods:

You can also chain filters like this:

Checkers

You can Check if $comment has replies or parent

You can also check if a commentable model hasCommentsBy an owner or the other way around:

Check if a $comment belongs to a related Model:

Commentable Table

The structure of the coments table is as follows:

License

This package is released under the MIT license (MIT).


All versions of commentable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^10.10
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package melsaka/commentable contains the following files

Loading the files please wait ....