Installation:
composer require usamamuneerchaudhary/commentify
php artisan vendor:publish --provider="UsamaMuneerChaudhary\Commentify\CommentifyServiceProvider" --tag="migrations"
php artisan migrate
Publish Config:
php artisan vendor:publish --provider="UsamaMuneerChaudhary\Commentify\CommentifyServiceProvider" --tag="config"
config/commentify.php for default settings (e.g., commentable models, UI preferences).First Use Case:
// In Post model
use UsamaMuneerChaudhary\Commentify\Traits\Commentable;
class Post extends Model
{
use Commentable;
}
@commentify('App\Models\Post', $post->id)
<livewire:commentify />
Model Integration:
use Commentable to any model to enable commenting.commentify() method in your model:
public function commentify()
{
return $this->morphTo();
}
Livewire Component:
<livewire:commentify /> in your Blade template.<livewire:commentify :model="$post" :commentableType="App\Models\Post" />
UI Customization:
resources/css/commentify.css (published by the package).@commentify('App\Models\Post', $post->id)
@slot('comment', $comment)
<div class="custom-comment">
{{ $comment->body }}
</div>
@endslot
@endcommentify
Validation & Rules:
CommentifyRules in AppServiceProvider:
use UsamaMuneerChaudhary\Commentify\Rules\CommentifyRules;
CommentifyRules::extend(function ($rule, $attribute, $value, $fail) {
if (strlen($value) < 10) {
$fail('Comments must be at least 10 characters.');
}
});
Nested Comments:
'nested_comments' => true,
<livewire:commentify :parentId="$comment->id" />
Model Morphing:
commentify() in custom models can break polymorphic relationships.morphTo() or a custom relationship:
public function commentify()
{
return $this->morphTo();
}
Livewire Key Conflicts:
<livewire:commentify /> components on the same page may cause hydration errors.<livewire:commentify key="comments-{{ $post->id }}" />
Tailwind Class Collisions:
.comment-body).!important sparingly; prefer scoped classes:
.commentify .custom-comment {
@apply bg-gray-100;
}
Rate Limiting:
throttle middleware or use CommentifyMiddleware:
'middleware' => [
\UsamaMuneerChaudhary\Commentify\Http\Middleware\CommentifyMiddleware::class,
],
Log Comment Events:
'debug' => env('COMMENTIFY_DEBUG', false),
storage/logs/laravel.log for Livewire/Commentify events.Wire:ignore for Static Content:
@wire:ignore
<div class="static-content">...</div>
@endwire
Database Seeding:
CommentifySeeder for testing:
php artisan db:seed --class=CommentifySeeder
Custom Comment Models:
Comment model:
class CustomComment extends \UsamaMuneerChaudhary\Commentify\Models\Comment
{
protected $table = 'custom_comments';
}
'model' => \App\Models\CustomComment::class,
Event Listeners:
CommentCreated):
use UsamaMuneerChaudhary\Commentify\Events\CommentCreated;
CommentCreated::listen(function ($comment) {
// Send notification, log, etc.
});
API Endpoints:
CommentifyController as a base for custom API routes:
Route::post('/comments', [\UsamaMuneerChaudhary\Commentify\Http\Controllers\CommentifyController::class, 'store']);
Localization:
php artisan vendor:publish --provider="UsamaMuneerChaudhary\Commentify\CommentifyServiceProvider" --tag="lang"
resources/lang/en/commentify.php.How can I help you explore Laravel packages today?