1. Go to this page and download the library: Download zepson/laravel-comments 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/ */
zepson / laravel-comments example snippets
$post = Post::find(1);
$post->comment('This is a comment');
$post->commentAsUser($user, 'This is a comment from someone else');
$post = Post::find(1);
$comment = $post->comment('This is a comment from a user.');
$post = Post::find(1);
$comment = $post->commentAsUser($yourUser, 'This is a comment from someone else.');
namespace App\Models;
use zepson\Comments\Contracts\Commentator;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements Commentator
{
/**
* Check if a comment for a specific model needs to be approved.
* @param mixed $model
* @return bool
*/
public function needsCommentApproval($model): bool
{
return false;
}
}
$post = Post::find(1);
// Retrieve all comments
$comments = $post->comments;
// Retrieve only approved comments
$approved = $post->comments()->approved()->get();