Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/filament-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
4 changes: 2 additions & 2 deletions database/migrations/add_index_to_subject.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
}
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/create_filament_comments_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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'));
}
};
12 changes: 12 additions & 0 deletions src/Models/FilamentComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
Expand Down