You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. In your `User` model implement the `Commenter` interface.
27
+
**2. In your `User` model implement the `Commenter` interface.**
28
28
29
29
```php
30
30
use Kirschbaum\Commentions\Contracts\Commenter;
@@ -35,7 +35,7 @@ class User extends Model implements Commenter
35
35
}
36
36
```
37
37
38
-
3. In the model you want to add comments, implement the `Commentable` interface and the `HasComments` trait.
38
+
**3. In the model you want to add comments, implement the `Commentable` interface and the `HasComments` trait.**
39
39
40
40
```php
41
41
use Kirschbaum\Commentions\HasComments;
@@ -47,7 +47,9 @@ class Project extends Model implements Commentable
47
47
}
48
48
```
49
49
50
-
4. Configure the Commentions paths in your Tailwind config:
50
+
**4. Configure the Commentions paths in your Tailwind config:**
51
+
52
+
If you don't have a [custom theme](https://filamentphp.com/docs/3.x/panels/themes#creating-a-custom-theme), you will have to configure. This is Filament's [recommendation](https://filamentphp.com/docs/3.x/support/assets#using-tailwind-css-in-plugins) if you are using Plugins.
51
53
52
54
```js
53
55
exportdefault {
@@ -60,22 +62,22 @@ export default {
60
62
}
61
63
```
62
64
63
-
5. Register the Commentions plugin:
65
+
**5. Register the Commentions plugin:**
66
+
67
+
You can register the plugin in your Panel(s) like so:
64
68
65
69
```php
66
70
use Kirschbaum\Commentions\CommentionsPlugin;
67
71
68
72
return $panel
69
73
->plugins([
70
-
CommentionsPlugin::make()
71
-
->disallowEdits() // Prevent users from editing their comments
72
-
->disallowDeletes() // Prevent users from deleting their comments
74
+
CommentionsPlugin::make(),
73
75
])
74
76
```
75
77
76
-
There are a couple of ways to use Commentions with Filament.
78
+
**6. Use the component**
77
79
78
-
1. Register the component in your Filament Infolists:
use Kirschbaum\Commentions\Filament\Actions\CommentsTableAction;
@@ -96,7 +98,7 @@ use Kirschbaum\Commentions\Filament\Actions\CommentsTableAction;
96
98
])
97
99
```
98
100
99
-
3.Or as a header action:
101
+
Or header actions:
100
102
101
103
```php
102
104
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
@@ -121,36 +123,61 @@ If your `User` model lives in a different namespace than `App\Models\User`, you
121
123
],
122
124
```
123
125
124
-
### Disabling comment editing and deletion
126
+
### Configuring the Comment model
127
+
128
+
If you need to customize the Comment model, you can extend the `\Kirschbaum\Commentions\Comment` class and then update the `comment.model` option in your `config/commentions.php` file:
129
+
130
+
```php
131
+
'comment' => [
132
+
'model' => \App\Models\Comment::class,
133
+
// ...
134
+
],
135
+
```
125
136
126
-
By default, users can edit and delete their own comments. You can disable this functionality in two ways:
137
+
### Configuring Comment permissions
127
138
128
-
#### 1. Using the plugin configuration
139
+
By default, users can create comments, as well as edit and delete their own comments. You can adjust these permissions by implementing your own policy:
140
+
141
+
#### 1) Create a custom policy
129
142
130
143
```php
131
-
use Kirschbaum\Commentions\CommentionsPlugin;
144
+
namespace App\Policies;
132
145
133
-
return $panel
134
-
->plugins([
135
-
CommentionsPlugin::make()
136
-
->disallowEdits() // Prevent users from editing their comments
137
-
->disallowDeletes() // Prevent users from deleting their comments
138
-
])
146
+
use Kirschbaum\Commentions\Comment;
147
+
use Kirschbaum\Commentions\Contracts\Commenter;
148
+
use Kirschbaum\Commentions\Policies\CommentPolicy;
149
+
150
+
class CommentPolicy extends CommentPolicy
151
+
{
152
+
public function create(Commenter $user): bool
153
+
{
154
+
// TODO: Implement custom permission logic.
155
+
}
156
+
157
+
public function update($user, Comment $comment): bool
158
+
{
159
+
// TODO: Implement custom permission logic.
160
+
}
161
+
162
+
public function delete($user, Comment $comment): bool
163
+
{
164
+
// TODO: Implement custom permission logic.
165
+
}
166
+
}
139
167
```
140
168
141
-
#### 2. Using the configuration file
169
+
#### 2) Register your policy in the configuration file
142
170
143
-
Set the `allow_edits` and `allow_deletes` options in your `config/commentions.php` file:
171
+
Update the `comment.policy` option in your `config/commentions.php` file:
144
172
145
173
```php
146
-
/**
147
-
* Comment editing/deleting options.
148
-
*/
149
-
'allow_edits' => false,
150
-
'allow_deletes' => false,
174
+
'comment' => [
175
+
// ...
176
+
'policy' => \App\Policies\CommentPolicy::class,
177
+
],
151
178
```
152
179
153
-
> **Note:** The plugin configuration takes precedence over the config file settings.
180
+
### Configuring the Commenter name
154
181
155
182
By default, the `name` property will be used to render the mention names. You can customize it either by implementing the Filament `HasName` interface OR by implementing the optional `getCommenterName` method.
156
183
@@ -278,6 +305,7 @@ If you discover any security related issues, please email security@kirschbaumdev
0 commit comments