Skip to content

Commit ac367d8

Browse files
committed
Make table name configurable
1 parent 66cb266 commit ac367d8

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

config/filament-comments.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@
5353
* Authenticatable model class
5454
*/
5555
'authenticatable' => \App\Models\User::class,
56+
57+
58+
/*
59+
* The name of the table where the comments are stored.
60+
*/
61+
'table_name' => 'filament_comments',
5662
];

database/migrations/add_index_to_subject.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ return new class extends Migration
88
{
99
public function up(): void
1010
{
11-
Schema::table('filament_comments', function (Blueprint $table) {
11+
Schema::table(config('filament-comments.table_name', 'filament_comments'), function (Blueprint $table) {
1212
$table->index(['subject_type', 'subject_id']);
1313
});
1414
}
1515

1616
public function down(): void
1717
{
18-
Schema::table('filament_comments', function (Blueprint $table) {
18+
Schema::table(config('filament-comments.table_name', 'filament_comments'), function (Blueprint $table) {
1919
$table->dropIndex(['subject_type', 'subject_id']);
2020
});
2121
}

database/migrations/create_filament_comments_table.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ return new class extends Migration
88
{
99
public function up()
1010
{
11-
Schema::create('filament_comments', function (Blueprint $table) {
11+
Schema::create(config('filament-comments.table_name', 'filament_comments'), function (Blueprint $table) {
1212
$table->id();
1313
$table->unsignedBigInteger('user_id');
1414
$table->string('subject_type');
@@ -21,6 +21,6 @@ return new class extends Migration
2121

2222
public function down()
2323
{
24-
Schema::dropIfExists('filament_comments');
24+
Schema::dropIfExists(config('filament-comments.table_name', 'filament_comments'));
2525
}
2626
};

src/Models/FilamentComment.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ class FilamentComment extends Model
2020
'comment',
2121
];
2222

23+
public function __construct(array $attributes = [])
24+
{
25+
$config = Config::get('filament-comments');
26+
27+
if (isset($config['table_name'])) {
28+
$this->setTable($config['table_name']);
29+
}
30+
31+
parent::__construct($attributes);
32+
}
33+
2334
public function user(): BelongsTo
2435
{
2536
$authenticatable = config('filament-comments.authenticatable');

0 commit comments

Comments
 (0)