PHP code example of tavaresevora / commentable

1. Go to this page and download the library: Download tavaresevora/commentable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tavaresevora / commentable example snippets

 php
    Tavaresevora\Commentable\CommentableServiceProvider::class,

  php artisan vendor:publish --tag=comment-migrations
  php artisan migrate
 php
    
    
    $post = App\Post::first();
    $user = Auth::user();
    $post->addComment('Superbe article !', $user);
    
    //addComment($body, Model $author, $validate = NULL);
 php
    
    
    $post = App\Post::first();
    $comment = $post->comments->first();
    $user = Auth::user();
    $post->updateComment($comment, $body)
    
    // If you want change the author
    $newUser = User::find(2);
    $post->updateComment($comment, $body, $newUser)
    
    //updateComment(Comment $comment, $body, Model $author = NULL)
 php
    
    
    $post = App\Post::first();
    $comment = $post->comments->first();
    $post->deleteComment($comment)
    
    //deleteComment(Comment $comment)
 php
    
    
    @foreach($post->comments as $comment)
        <p>
            {{ $comment->body }} - <span>{{ $comment->author->name }}</span>
        </p>
    @endforeach