diff --git a/config/comments.php b/config/comments.php index 0552125..abe18f0 100644 --- a/config/comments.php +++ b/config/comments.php @@ -1,19 +1,29 @@ [ - 'comments' => 'comments', - ], - 'models' => [ 'comment' => Comment::class, ], + 'table_names' => [ + 'comments' => 'comments', + 'reactions' => 'comment_reactions', + 'mentions' => 'comment_mentions', + 'subscriptions' => 'comment_subscriptions', + 'attachments' => 'comment_attachments', + ], + + 'column_names' => [ + 'commenter_morph' => 'commenter', + ], + 'commenter' => [ 'model' => User::class, ], diff --git a/database/factories/CommentFactory.php b/database/factories/CommentFactory.php index 55cdeec..04b50ea 100644 --- a/database/factories/CommentFactory.php +++ b/database/factories/CommentFactory.php @@ -3,7 +3,7 @@ namespace Relaticle\Comments\Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -use Relaticle\Comments\Comment; +use Relaticle\Comments\Models\Comment; class CommentFactory extends Factory { diff --git a/database/migrations/create_comment_attachments_table.php.stub b/database/migrations/create_comment_attachments_table.php.stub index a04f830..0e3c65f 100644 --- a/database/migrations/create_comment_attachments_table.php.stub +++ b/database/migrations/create_comment_attachments_table.php.stub @@ -8,10 +8,10 @@ return new class extends Migration { public function up(): void { - Schema::create('comment_attachments', function (Blueprint $table) { + Schema::create(config('comments.table_names.attachments', 'comment_attachments'), function (Blueprint $table) { $table->id(); $table->foreignId('comment_id') - ->constrained(config('comments.tables.comments', 'comments')) + ->constrained(config('comments.table_names.comments', 'comments')) ->cascadeOnDelete(); $table->string('file_path'); $table->string('original_name'); diff --git a/database/migrations/create_comment_mentions_table.php.stub b/database/migrations/create_comment_mentions_table.php.stub index f48e957..787b1e5 100644 --- a/database/migrations/create_comment_mentions_table.php.stub +++ b/database/migrations/create_comment_mentions_table.php.stub @@ -8,15 +8,15 @@ return new class extends Migration { public function up(): void { - Schema::create('comment_mentions', function (Blueprint $table) { + Schema::create(config('comments.table_names.mentions', 'comment_mentions'), function (Blueprint $table) { $table->id(); $table->foreignId('comment_id') - ->constrained(config('comments.tables.comments', 'comments')) + ->constrained(config('comments.table_names.comments', 'comments')) ->cascadeOnDelete(); - $table->morphs('user'); + $table->morphs('commenter'); $table->timestamps(); - $table->unique(['comment_id', 'user_id', 'user_type']); + $table->unique(['comment_id', 'commenter_id', 'commenter_type']); }); } }; diff --git a/database/migrations/create_comment_reactions_table.php.stub b/database/migrations/create_comment_reactions_table.php.stub index 79422c2..5a9eb54 100644 --- a/database/migrations/create_comment_reactions_table.php.stub +++ b/database/migrations/create_comment_reactions_table.php.stub @@ -8,16 +8,16 @@ return new class extends Migration { public function up(): void { - Schema::create('comment_reactions', function (Blueprint $table) { + Schema::create(config('comments.table_names.reactions', 'comment_reactions'), function (Blueprint $table) { $table->id(); $table->foreignId('comment_id') - ->constrained(config('comments.tables.comments', 'comments')) + ->constrained(config('comments.table_names.comments', 'comments')) ->cascadeOnDelete(); - $table->morphs('user'); + $table->morphs('commenter'); $table->string('reaction'); $table->timestamps(); - $table->unique(['comment_id', 'user_id', 'user_type', 'reaction']); + $table->unique(['comment_id', 'commenter_id', 'commenter_type', 'reaction']); }); } }; diff --git a/database/migrations/create_comment_subscriptions_table.php.stub b/database/migrations/create_comment_subscriptions_table.php.stub index f5872b9..6c1861b 100644 --- a/database/migrations/create_comment_subscriptions_table.php.stub +++ b/database/migrations/create_comment_subscriptions_table.php.stub @@ -8,13 +8,13 @@ return new class extends Migration { public function up(): void { - Schema::create('comment_subscriptions', function (Blueprint $table) { + Schema::create(config('comments.table_names.subscriptions', 'comment_subscriptions'), function (Blueprint $table) { $table->id(); $table->morphs('commentable'); - $table->morphs('user'); + $table->morphs('commenter'); $table->timestamp('created_at')->nullable(); - $table->unique(['commentable_type', 'commentable_id', 'user_type', 'user_id'], 'comment_subscriptions_unique'); + $table->unique(['commentable_type', 'commentable_id', 'commenter_type', 'commenter_id'], 'comment_subscriptions_unique'); }); } }; diff --git a/database/migrations/create_comments_table.php.stub b/database/migrations/create_comments_table.php.stub index 80c0694..eaaa5df 100644 --- a/database/migrations/create_comments_table.php.stub +++ b/database/migrations/create_comments_table.php.stub @@ -8,13 +8,13 @@ return new class extends Migration { public function up(): void { - Schema::create(config('comments.tables.comments', 'comments'), function (Blueprint $table) { + Schema::create(config('comments.table_names.comments', 'comments'), function (Blueprint $table) { $table->id(); $table->morphs('commentable'); - $table->morphs('user'); + $table->morphs('commenter'); $table->foreignId('parent_id') ->nullable() - ->constrained(config('comments.tables.comments', 'comments')) + ->constrained(config('comments.table_names.comments', 'comments')) ->cascadeOnDelete(); $table->text('body'); $table->timestamp('edited_at')->nullable(); diff --git a/docs/.data/content/contents.sqlite b/docs/.data/content/contents.sqlite new file mode 100644 index 0000000..178b545 Binary files /dev/null and b/docs/.data/content/contents.sqlite differ diff --git a/resources/lang/en/comments.php b/resources/lang/en/comments.php index 840703b..bc95431 100644 --- a/resources/lang/en/comments.php +++ b/resources/lang/en/comments.php @@ -1,9 +1,58 @@ 'This comment was deleted.', - 'edited' => 'edited', - 'load_more' => 'Load more comments', - 'no_comments' => 'No comments yet.', - 'comment_placeholder' => 'Write a comment...', + 'comments' => [ + 'deleted' => 'This comment was deleted.', + 'edited' => 'edited', + 'no_comments' => 'No comments yet.', + 'placeholder' => 'Write a comment...', + 'load_more' => 'Load more comments', + 'sort_newest' => 'Newest first', + 'sort_oldest' => 'Oldest first', + ], + + 'actions' => [ + 'reply' => 'Reply', + 'edit' => 'Edit', + 'delete' => 'Delete', + 'cancel' => 'Cancel', + 'save' => 'Save', + 'submit' => 'Submit', + ], + + 'reactions' => [ + 'thumbs_up' => 'Thumbs up', + 'heart' => 'Heart', + 'celebrate' => 'Celebrate', + 'laugh' => 'Laugh', + 'thinking' => 'Thinking', + 'sad' => 'Sad', + 'reacted_by' => ':names reacted with :reaction', + 'and_others' => 'and :count others', + ], + + 'subscriptions' => [ + 'subscribe' => 'Subscribe to replies', + 'unsubscribe' => 'Unsubscribe from replies', + 'subscribed' => 'You will be notified of new replies.', + 'unsubscribed' => 'You will no longer be notified.', + ], + + 'mentions' => [ + 'no_results' => 'No users found', + ], + + 'attachments' => [ + 'add' => 'Add attachment', + 'remove' => 'Remove', + 'too_large' => 'File is too large. Maximum size: :max KB.', + 'invalid_type' => 'File type not allowed.', + ], + + 'notifications' => [ + 'reply_subject' => 'New reply to your comment', + 'reply_body' => ':name replied to your comment.', + 'mention_subject' => 'You were mentioned in a comment', + 'mention_body' => ':name mentioned you in a comment.', + ], ]; diff --git a/resources/views/livewire/comment-item.blade.php b/resources/views/livewire/comment-item.blade.php index 2d5e06e..4ab5981 100644 --- a/resources/views/livewire/comment-item.blade.php +++ b/resources/views/livewire/comment-item.blade.php @@ -3,11 +3,11 @@
{{ $message }}
@enderror - @if (\Relaticle\Comments\Config::areAttachmentsEnabled()) + @if (\Relaticle\Comments\CommentsConfig::areAttachmentsEnabled())