diff --git a/config/filament-comments.php b/config/filament-comments.php index 57c7aa5..110562a 100644 --- a/config/filament-comments.php +++ b/config/filament-comments.php @@ -53,4 +53,10 @@ * Authenticatable model class */ 'authenticatable' => \App\Models\User::class, + + + /* + * The name of the table where the comments are stored. + */ + 'table_name' => 'filament_comments', ]; diff --git a/database/migrations/add_index_to_subject.php.stub b/database/migrations/add_index_to_subject.php.stub index 7b901a5..4380c37 100644 --- a/database/migrations/add_index_to_subject.php.stub +++ b/database/migrations/add_index_to_subject.php.stub @@ -8,14 +8,14 @@ return new class extends Migration { public function up(): void { - Schema::table('filament_comments', function (Blueprint $table) { + Schema::table(config('filament-comments.table_name', 'filament_comments'), function (Blueprint $table) { $table->index(['subject_type', 'subject_id']); }); } public function down(): void { - Schema::table('filament_comments', function (Blueprint $table) { + Schema::table(config('filament-comments.table_name', 'filament_comments'), function (Blueprint $table) { $table->dropIndex(['subject_type', 'subject_id']); }); } diff --git a/database/migrations/create_filament_comments_table.php.stub b/database/migrations/create_filament_comments_table.php.stub index 57a6409..671c374 100644 --- a/database/migrations/create_filament_comments_table.php.stub +++ b/database/migrations/create_filament_comments_table.php.stub @@ -8,7 +8,7 @@ return new class extends Migration { public function up() { - Schema::create('filament_comments', function (Blueprint $table) { + Schema::create(config('filament-comments.table_name', 'filament_comments'), function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('user_id'); $table->string('subject_type'); @@ -21,6 +21,6 @@ return new class extends Migration public function down() { - Schema::dropIfExists('filament_comments'); + Schema::dropIfExists(config('filament-comments.table_name', 'filament_comments')); } }; diff --git a/src/Models/FilamentComment.php b/src/Models/FilamentComment.php index e99832b..a75b7bf 100644 --- a/src/Models/FilamentComment.php +++ b/src/Models/FilamentComment.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Facades\Config; class FilamentComment extends Model { @@ -20,6 +21,17 @@ class FilamentComment extends Model 'comment', ]; + public function __construct(array $attributes = []) + { + $config = Config::get('filament-comments'); + + if (isset($config['table_name'])) { + $this->setTable($config['table_name']); + } + + parent::__construct($attributes); + } + public function user(): BelongsTo { $authenticatable = config('filament-comments.authenticatable');