refactor: rename for Laravel conventions and better DX
- Rename IsCommenter trait to CanComment, Commenter interface to Commentator - Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription) - Rename user_type/user_id polymorphic columns to commenter_type/commenter_id - Rename Config class to CommentsConfig, update config key tables->table_names - Rename getCommentName() to getCommentDisplayName() on commentator models - Add column_names config section for commenter morph customization - Add table_names config with all 5 tables individually configurable - Expand translation file with structured i18n groups - Update all Blade views, Livewire components, events, listeners, and tests
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user