2
2
3
3
namespace Parallax \FilamentComments \Livewire ;
4
4
5
- use App \Models \Comment ;
6
5
use Filament \Forms ;
7
6
use Filament \Forms \Concerns \InteractsWithForms ;
8
7
use Filament \Forms \Contracts \HasForms ;
9
8
use Filament \Forms \Form ;
9
+ use Filament \Notifications \Notification ;
10
10
use Illuminate \Contracts \View \View ;
11
11
use Illuminate \Database \Eloquent \Model ;
12
12
use Livewire \Component ;
@@ -27,32 +27,28 @@ public function mount(): void
27
27
28
28
public function form (Form $ form ): Form
29
29
{
30
+ if (!auth ()->user ()->can ('create ' , FilamentComment::class)) {
31
+ return $ form ;
32
+ }
33
+
30
34
return $ form
31
35
->schema ([
32
36
Forms \Components \RichEditor::make ('comment ' )
33
37
->hiddenLabel ()
34
38
->required ()
35
39
->placeholder (__ ('filament-comments::filament-comments.comments.placeholder ' ))
36
40
->extraInputAttributes (['style ' => 'min-height: 6rem ' ])
37
- ->toolbarButtons ([
38
- 'blockquote ' ,
39
- 'bold ' ,
40
- 'bulletList ' ,
41
- 'codeBlock ' ,
42
- 'italic ' ,
43
- 'link ' ,
44
- 'orderedList ' ,
45
- 'redo ' ,
46
- 'strike ' ,
47
- 'underline ' ,
48
- 'undo ' ,
49
- ])
41
+ ->toolbarButtons (config ('filament-comments.toolbar_buttons ' ))
50
42
])
51
43
->statePath ('data ' );
52
44
}
53
45
54
46
public function create (): void
55
47
{
48
+ if (!auth ()->user ()->can ('create ' , FilamentComment::class)) {
49
+ return ;
50
+ }
51
+
56
52
$ this ->form ->validate ();
57
53
58
54
$ data = $ this ->form ->getState ();
@@ -63,12 +59,32 @@ public function create(): void
63
59
'user_id ' => auth ()->id (),
64
60
]);
65
61
62
+ Notification::make ()
63
+ ->title (__ ('filament-comments::filament-comments.notifications.created ' ))
64
+ ->success ()
65
+ ->send ();
66
+
66
67
$ this ->form ->fill ();
67
68
}
68
69
69
70
public function delete (int $ id ): void
70
71
{
71
- FilamentComment::find ($ id )->delete ();
72
+ $ comment = FilamentComment::find ($ id );
73
+
74
+ if (!$ comment ) {
75
+ return ;
76
+ }
77
+
78
+ if (!auth ()->user ()->can ('delete ' , $ comment )) {
79
+ return ;
80
+ }
81
+
82
+ $ comment ->delete ();
83
+
84
+ Notification::make ()
85
+ ->title (__ ('filament-comments::filament-comments.notifications.deleted ' ))
86
+ ->success ()
87
+ ->send ();
72
88
}
73
89
74
90
public function render (): View
0 commit comments