1. Go to this page and download the library: Download businesstilto/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/ */
businesstilto / commentable example snippets
return [
/*
|--------------------------------------------------------------------------
| Comment model
|--------------------------------------------------------------------------
*/
'comment' => [
'model' => Tilto\Commentable\Models\Comment::class,
'policy' => Tilto\Commentable\Policies\CommentPolicy::class,
],
/*
|--------------------------------------------------------------------------
| Reply
|--------------------------------------------------------------------------
*/
'reply' => [
'allow_self_reply' => false,
],
/*
|--------------------------------------------------------------------------
| Editor
|--------------------------------------------------------------------------
|
| 'submit_shortcut' controls the keyboard shortcut for submitting a comment:
| - 'mod+enter': Ctrl + Enter (Windows/Linux) or Cmd + Enter (macOS)
| - 'enter': Enter submits, Shift + Enter inserts a new line
| - false: no keyboard shortcut
|
*/
'editor' => [
'submit_shortcut' => 'mod+enter',
],
/*
|--------------------------------------------------------------------------
| Reaction
|--------------------------------------------------------------------------
*/
'reaction' => [
'model' => Tilto\Commentable\Models\CommentReaction::class,
'allowed' => ['👍', '❤️', '😂', '😮', '😢', '🤔'],
'show_reactors_tooltip' => true,
],
];
use Tilto\Commentable\Contracts\Commenter;
use Tilto\Commentable\Traits\IsCommenter;
class User extends Model implements Commenter
{
use isCommenter;
}
use Tilto\Commentable\Traits\HasComments;
use Tilto\Commentable\Contracts\Commentable;
class Post extends Model implements Commentable
{
use HasComments;
}
namespace App\Policies;
use Tilto\Commentable\Contracts\Commenter;
use Tilto\Commentable\Models\Comment;
use Tilto\Commentable\Policies\CommentPolicy as CommentablePolicy;
class CommentPolicy extends CommentablePolicy
{
public function create(Commenter $user): bool
{
// ...
}
public function update(Commenter $user, Comment $comment): bool
{
// ...
}
public function reply(Commenter $user, Comment $comment): bool
{
// ...
}
public function delete(Commenter $user, Comment $comment): bool
{
// ...
}
}
use Tilto\Commentable\Events\CommentCreatedEvent;
class NotifyOnCommentCreated
{
public function handle(CommentCreatedEvent $event): void
{
// Access the created comment:
$comment = $event->comment;
// Add your custom logic here, e.g., send a notification
}
}
CommentsEntry::make('comments')
->fileAttachmentsDisk('public') // Set the storage disk for attachments
->fileAttachmentsVisibility('public') // Set the storage visibility for attachments
->fileAttachmentsDirectory('comments') // Set the directory for attachments
->fileAttachmentsAcceptedFileTypes(['pdf', 'jpg', 'png']) // Set accepted file types
->fileAttachmentsMaxSize(5120) // Set max file size in kilobytes
CommentsEntry::make('comments')
->pollInterval('5s') // Refresh every 5 seconds
CommentsEntry::make('comments')
->enablePolling() // Refresh using the default interval