Added example for nesting comments to Readme

This commit is contained in:
Di
2024-02-13 18:03:03 +01:00
parent b5569cce2b
commit cd2f65ed92
+12 -4
View File
@@ -1,8 +1,6 @@
# Add comments to your Laravel application # Add comments to your Laravel application
[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-comments.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-comments) [![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-comments.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-comments)
[![Build Status](https://img.shields.io/travis/beyondcode/laravel-comments/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-comments)
[![Quality Score](https://img.shields.io/scrutinizer/g/beyondcode/laravel-comments.svg?style=flat-square)](https://scrutinizer-ci.com/g/beyondcode/laravel-comments)
[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-comments.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-comments) [![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-comments.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-comments)
Add the ability to associate comments to your Laravel Eloquent models. The comments can be approved and nested. Add the ability to associate comments to your Laravel Eloquent models. The comments can be approved and nested.
@@ -115,9 +113,9 @@ class User extends Authenticatable implements Commentator
*/ */
public function needsCommentApproval($model): bool public function needsCommentApproval($model): bool
{ {
return false; return false;
} }
} }
``` ```
@@ -139,6 +137,16 @@ $approved = $post->comments()->approved()->get();
``` ```
### Nesting Comments
`BeyondCode\Comments\Comment` itself implements the `HasComments` trait, so you can comment on a comment and therefore nest them:
```php
$comment = BeyondCode\Comments\Comment::first();
$comment->commentAsUser($user, "Hey there!");
```
### Testing ### Testing
``` bash ``` bash