Skip to content

Commit c796d0b

Browse files
Merge pull request #43 from ziming/patch-3
Config setting to change model class
2 parents a289f3e + 14c3440 commit c796d0b

File tree

7 files changed

+13
-7
lines changed

7 files changed

+13
-7
lines changed

config/filament-comments.php

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
'empty' => 'heroicon-s-chat-bubble-left-right',
1616
],
1717

18+
19+
/*
20+
* The comment model to be used
21+
*/
22+
'comment_model' => \Parallax\FilamentComments\Models\FilamentComment::class,
23+
1824
/*
1925
* The policy that will be used to authorize actions against comments.
2026
*/

src/Actions/CommentsAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ protected function setUp(): void
2929
->modalWidth(MaxWidth::Medium)
3030
->modalSubmitAction(false)
3131
->modalCancelAction(false)
32-
->visible(fn (): bool => auth()->user()->can('viewAny', FilamentComment::class));
32+
->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model'));
3333
}
3434
}

src/FilamentCommentsServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function packageBooted(): void
5555
{
5656
Livewire::component('comments', CommentsComponent::class);
5757

58-
Gate::policy(FilamentComment::class, config('filament-comments.model_policy', FilamentCommentPolicy::class));
58+
Gate::policy(config('filament-comments.comment_model'), config('filament-comments.model_policy', FilamentCommentPolicy::class));
5959

6060
FilamentAsset::register(
6161
$this->getAssets(),

src/Infolists/Components/CommentsEntry.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ protected function setUp(): void
1313
{
1414
parent::setUp();
1515

16-
$this->visible(fn (): bool => auth()->user()->can('viewAny', FilamentComment::class));
16+
$this->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model')));
1717
}
1818
}

src/Livewire/CommentsComponent.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function mount(): void
2727

2828
public function form(Form $form): Form
2929
{
30-
if (!auth()->user()->can('create', FilamentComment::class)) {
30+
if (!auth()->user()->can('create', config('filament-comments.comment_model'))) {
3131
return $form;
3232
}
3333

@@ -45,7 +45,7 @@ public function form(Form $form): Form
4545

4646
public function create(): void
4747
{
48-
if (!auth()->user()->can('create', FilamentComment::class)) {
48+
if (!auth()->user()->can('create', config('filament-comments.comment_model'))) {
4949
return;
5050
}
5151

src/Models/Traits/HasFilamentComments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait HasFilamentComments
1010
public function filamentComments(): HasMany
1111
{
1212
return $this
13-
->hasMany(FilamentComment::class, 'subject_id')
13+
->hasMany(config('filament-comments.comment_model'), 'subject_id')
1414
->where('subject_type', $this->getMorphClass())
1515
->latest();
1616
}

src/Tables/Actions/CommentsAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ protected function setUp(): void
3030
->modalWidth(MaxWidth::Medium)
3131
->modalSubmitAction(false)
3232
->modalCancelAction(false)
33-
->visible(fn (): bool => auth()->user()->can('viewAny', FilamentComment::class));
33+
->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model')));
3434
}
3535
}

0 commit comments

Comments
 (0)