PHPackages                             avihs/laravel-post-comment-reply - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. avihs/laravel-post-comment-reply

ActiveLibrary[Database &amp; ORM](/categories/database)

avihs/laravel-post-comment-reply
================================

This will create a post, comment, likes and reply &amp; save in database

1.0.3(5y ago)71102[2 issues](https://github.com/shivragshukla/laravel-post-comment-reply/issues)MITPHPPHP ^7.2.5

Since Sep 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/shivragshukla/laravel-post-comment-reply)[ Packagist](https://packagist.org/packages/avihs/laravel-post-comment-reply)[ RSS](/packages/avihs-laravel-post-comment-reply/feed)WikiDiscussions master Synced today

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Laravel Post Comment Reply
==========================

[](#laravel-post-comment-reply)

[![GitHub issues](https://camo.githubusercontent.com/d68e3611d2ec072fd9db23d725ad234c2c5cd5707c008339dcd8962ba7f026c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736869767261677368756b6c612f6c61726176656c2d706f73742d636f6d6d656e742d7265706c79)](https://github.com/shivragshukla/laravel-post-comment-reply/issues)[![GitHub license](https://camo.githubusercontent.com/04a9598681da321fa927067444fc54c02b139051805222b3ffc7cd1e7b302744/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736869767261677368756b6c612f6c61726176656c2d706f73742d636f6d6d656e742d7265706c79)](https://github.com/shivragshukla/laravel-post-comment-reply/blob/master/LICENSE)

This will create a post, comment and reply &amp; save in database.

- [Installation](#installation)
- [Usage](#usage)
- [Blade](#blade)
- [Advance Eloquent Model](#advance-eloquent-model)
- [Example](#example)

> ⚠️ this add-on is developed to be backwards compatible down to Laravel 5.6+

Installation
------------

[](#installation)

Use the composer require or add to composer.json.

```
composer require avihs/laravel-post-comment-reply
```

If you are using SQL database server to store log events you would need to run the migrations first. The MongoDB driver does not require the migration.

```
php artisan migrate
```

Usage
-----

[](#usage)

Since this is a custom package, and your Model should have User and database users table.

### Basic Usage

[](#basic-usage)

First, add the ***use Avihs\\PostReply\\Traits\\HasPost*** trait to your User model:

```
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Avihs\PostReply\Traits\HasPost;

class User extends Authenticatable
{
    use HasPost;

    // ...
}
```

### User

[](#user)

```
// Fetch the User
$user = User::find(1);

// get User Posts
$posts =  $user->posts;
// get latest Posts
$latestPosts =  $user->latest_posts;

// get Active Posts
$activePosts =  $user->active_posts;

// get Active Posts
$inactivePosts =  $user->inactive_posts;

// Post Count
$postsCount =  $user->posts_count;
// Active Post Count
$activePostsCount =  $user->active_posts_count;
// Inactive Post Count
$inactivePostsCount =  $user->inactive_posts_count;

/**
 * Assgin or remove Post
 * Create or fetch the Post
**/

use Avihs\PostReply\Models\Post;
//Get the single Post or Post::find(1);
$post = Post::create([
        'title'=> 'My First Post',
        'description'=> 'This package will create posts, comments, likes, diskies and replies',
        'status'=> 1, // default active(1) for inactive(0)
    ]);

//Assign single Post
$user->assignPost($post);
//Assign multiple Post
$user->assignPost([$post, $post2]);

//Remove single Post
$user->removePost($post);
//Remove multiple Post
$user->removePost([$post, $post2]);

//Synchronize single Post
$user->syncPosts($post);
//Synchronize multiple Post
$user->syncPosts([$post, $post2]);
```

### Posts

[](#posts)

```
use Avihs\PostReply\Models\Post;
/**
 * Get all Posts
 * @return Array|Posts|Comments|Replies
 * Response all Posts with their comments and replies on each comment
**/
$posts = Post::all();

/**
 * Fetch a single Post
 * @return Object|Posts, Array|Comments|Replies
 * Response Post with all comments and replies on each comment
**/
$post = Post::find(1);

// Create new Post
$post = Post::create([
        'title'=> 'My First Post',
        'description'=> 'This package will create posts, comments, likes, diskies and replies',
        'status'=> 1, // default active(1) for inactive(0)
    ]);

// Update Post
$post->update(['title'=>'new text1']); // Boolean

/**
 * Delete Post
 * @return Boolean
 * This will delete the Post as well as all comments & replies of that Post
**/
$post->delete();

//Assign a Post to user
$post->user()->associate($user)->save();

//Remove a Post
$post->user()->dissociate()->save();

// First and Last Post for the User
$post = $user->posts->first();
$post = $user->posts->last();
```

### Comments

[](#comments)

```
/**
 * Get all Comments for the Post
 * @return Array|Comments|Replies
 * Response all comments and replies for the Post
**/

$comments = $post->comments;

/**
 * Add Comment to Post
 * 	@return Object|Comment with replies[]
**/
$comment = $post->addComment("My First Comment", $user);

/**
 * Add Comment to Post
 * @return Array|Comments|replies
 * Response all comments added to the post
**/
$comments = $post->addAllComments("This is awesome package", $user);

/**
 * Edit Comment to Post
 * @return Object|Comment with Array|replies
 * Response edited comment with replies
**/
$comment = $comment->editComment("My Edit Comment" , $OptionalParamsStatus =1);

/**
 * Delete Comment
 * @return Boolean
 * This will delete the Comment as well as all replies of that Comment
**/
$comment->delete();

// First and Last Comment for the Post
$comment = $post->comments->first();
$comment = $post->comments->last();

/**
 * Fetching a single comment
 * Get comment details
**/
use Avihs\PostReply\Models\Comment;

$comment = Comment::find(1); // OR $post->addComment("My First Comment", $user);

$commentText = $comment->content; //comment content
$commentDate =  $comment->created_at; //comment created date
$commentUpdate = $comment->updated_at; //comment updated date
$commentedByUser = $comment->user; // commented user in Object
```

### Replies

[](#replies)

```
/**
 * Get all Replies for the Comment
 * @return Array|Replies
 * Response all Replies for the Comment
**/

$replies = $comment->replies;

/**
 * Add Reply to Comment
 * 	@return Object|Reply
**/
$reply = $comment->addReply("My First Reply", $user);

/**
 * Add Reply to Comment
 * @return Array|Replies
 * Response all Replies added to the comment
**/
$replies = $comment->addAllReplies("This is awesome package, I like reply feature.", $user);

/**
 * Edit Reply to Comment
 * @return Object|Reply
 * Response edited reply
**/
$reply = $reply->editReply("My Edit Reply" , $OptionalParamsStatus =1);

/**
 * Delete Reply
 * @return Boolean
 * This will delete the Reply
**/
$reply->delete();

// First and Last Reply for the Comment
$reply = $comment->replies->first();
$reply = $comment->replies->last();

/**
 * Fetching a single reply
 * Get reply details
**/
use Avihs\PostReply\Models\Reply;

$reply = Reply::find(1); // OR $comment->addReply("My First Reply", $user);

$replyText = $reply->content; //reply content
$replyDate =  $reply->created_at; //reply created date
$replyUpdate = $reply->updated_at; //reply updated date
$repliedByUser = $reply->user; // replied user in Object
```

Blade
-----

[](#blade)

Can also use in laravel blade file.

```
@foreach ($posts as $post)

    Post Id : {{ $post->id }}
    Post title : {{ $post->title }}
    Post description : {{ $post->description }}
    Post status : {{ $post->status }}
    Post created date : {{ $post->created_at }}
    Post created by User : {{ $post->user->name }}
    Comments on Post:
      @foreach ($post->comments as $comment)

          Comment : {{ $comment->content }}
          Comment created date: {{ $comment->created_at }}
          Comment created by User: {{ $comment->user->name }}
          Reply on comment :
            @foreach ($comment->replies as $reply)

                Reply : {{ $reply->content }}
                Reply created date: {{ $reply->created_at }}
                Reply created by User: {{ $reply->user->name }}

            @endforeach

      @endforeach

@endforeach
```

Advance Eloquent Model
----------------------

[](#advance-eloquent-model)

Used with &amp; withCount

```
use Avihs\PostReply\Models\Post;

$posts = Post::with('user')->where('user_id', 1)->first();
$user = User::with(['posts', 'active_posts',  'inactive_posts', 'latest_posts'])->withCount(['posts', 'active_posts', 'inactive_posts'])->get();
```

Example
-------

[](#example)

Can use factory to create dummy data, You may also create a Collection of many models or create models of a given type:

```
php artisan tinker

factory(Avihs\PostReply\Models\Message::class,50)->create();
```

Single Post response

```
{
   "id":5,
   "title":"Post Ducimus sint id ut odit vel vel.",
   "description":"Vel sit iusto repellat aliquid excepturi accusamus aut. Omnis impedit ut sequi rerum ab vitae ea non. Ducimus et vero voluptas nesciunt. Qui dolores praesentium unde tenetur qui.",
   "status":0,
   "user_id":1,
   "created_at":"2020-09-03T13:09:19.000000Z",
   "updated_at":"2020-09-03T13:29:27.000000Z",
   "user":{
      "id":1,
      "name":"Shivrag Shukla",
      "email":"ines52@example.org",
      "email_verified_at":"2020-09-03T13:09:18.000000Z",
      "created_at":"2020-09-03T13:09:18.000000Z",
      "updated_at":"2020-09-03T13:09:18.000000Z"
   },
   "comments":[
      {
         "id":76,
         "content":"First Comment",
         "status":1,
         "created_at":"2020-09-03T18:37:31.000000Z",
         "updated_at":"2020-09-03T18:37:31.000000Z",
         "user":{
            "id":2,
            "name":"Tanya Powlowski",
            "email":"ines52@example.org",
            "email_verified_at":"2020-09-03T13:09:18.000000Z",
            "created_at":"2020-09-03T13:09:18.000000Z",
            "updated_at":"2020-09-03T13:09:18.000000Z"
         },
         "replies":[
            {
               "id":3,
               "content":"First Reply",
               "status":1,
               "created_at":"2020-09-03T13:09:30.000000Z",
               "updated_at":"2020-09-03T13:09:30.000000Z",
               "user":{
                  "id":14,
                  "name":"Mr. Zion Krajcik",
                  "email":"damaris.stamm@example.org",
                  "email_verified_at":"2020-09-03T13:09:19.000000Z",
                  "created_at":"2020-09-03T13:09:19.000000Z",
                  "updated_at":"2020-09-03T13:09:19.000000Z"
               }
            },
            {
               "id":30,
               "content":"Another Reply",
               "status":1,
               "created_at":"2020-09-03T13:09:30.000000Z",
               "updated_at":"2020-09-03T13:09:30.000000Z",
               "user":{
                  "id":4,
                  "name":"Mr. Shiva Shukla",
                  "email":"damaris.stamm@example.org",
                  "email_verified_at":"2020-09-03T13:09:19.000000Z",
                  "created_at":"2020-09-03T13:09:19.000000Z",
                  "updated_at":"2020-09-03T13:09:19.000000Z"
               }
            }
         ]
      },
      {
         "id":77,
         "content":"Another comment",
         "status":1,
         "created_at":"2020-09-03T18:37:44.000000Z",
         "updated_at":"2020-09-03T18:37:44.000000Z",
         "user":{
            "id":2,
            "name":"Tanya Powlowski",
            "email":"ines52@example.org",
            "email_verified_at":"2020-09-03T13:09:18.000000Z",
            "created_at":"2020-09-03T13:09:18.000000Z",
            "updated_at":"2020-09-03T13:09:18.000000Z"
         },
         "replies":[

         ]
      }
   ]
}
```

Development supported by: Shivrag Shukla
For any doubts contact :

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2074d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30346330?v=4)[Shivrag Shukla](/maintainers/shivragshukla)[@shivragshukla](https://github.com/shivragshukla)

---

Top Contributors

[![shivragshukla](https://avatars.githubusercontent.com/u/30346330?v=4)](https://github.com/shivragshukla "shivragshukla (10 commits)")

---

Tags

commentspostsreplies

### Embed Badge

![Health badge](/badges/avihs-laravel-post-comment-reply/health.svg)

```
[![Health](https://phpackages.com/badges/avihs-laravel-post-comment-reply/health.svg)](https://phpackages.com/packages/avihs-laravel-post-comment-reply)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)[hipsterjazzbo/landlord

A simple, single database multi-tenancy solution for Laravel 5.2+

613270.0k1](/packages/hipsterjazzbo-landlord)[stancl/virtualcolumn

Eloquent virtual column.

826.8M13](/packages/stancl-virtualcolumn)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
