1. Go to this page and download the library: Download lenorix/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/ */
lenorix / laravel-comments example snippets
use Illuminate\Database\Eloquent\Model;
use Lenorix\LaravelComments\Models\Concerns\HasComments;
use Lenorix\LaravelComments\Models\Concerns\Interfaces\Commentable;
class Post extends Model implements Commentable
{
use HasComments;
public function commentableName(): string
{
return $this->title;
}
public function commentUrl(): string
{
return route('posts.show', $this);
}
}
use Illuminate\Foundation\Auth\User as Authenticatable;
use Lenorix\LaravelComments\Models\Concerns\InteractsWithComments;
use Lenorix\LaravelComments\Models\Concerns\Interfaces\CanComment;
class User extends Authenticatable implements CanComment
{
use InteractsWithComments;
}
$post->comment('Great read!'); // as the current authenticated user
$post->comment('Great read!', $anotherUser); // on behalf of a specific user
$post->comments; // all comments, replies
$comment = $post->comment('Great read!');
$reply = $comment->comment('I agree!');
$comment->comments; // replies to this specific comment