16
16
use Filament \Forms \Form ;
17
17
use Filament \Notifications \Notification ;
18
18
use Illuminate \Contracts \View \View ;
19
- use Illuminate \Database \Eloquent \Builder ;
20
19
use Illuminate \Support \Facades \Auth ;
21
20
use Illuminate \Support \Facades \Blade ;
22
21
use Illuminate \Support \HtmlString ;
@@ -37,17 +36,15 @@ final class ArticleForm extends SlideOverComponent implements HasForms
37
36
38
37
public function mount (?int $ articleId = null ): void
39
38
{
40
- /** @var Article $article */
41
- $ article = $ articleId
39
+ // @phpstan-ignore-next-line
40
+ $ this -> article = $ articleId
42
41
? Article::query ()->findOrFail ($ articleId )
43
42
: new Article ;
44
43
45
- $ this ->form ->fill (array_merge ($ article ->toArray (), [
46
- 'is_draft ' => ! $ article ->published_at ,
47
- 'published_at ' => $ article ->published_at ,
44
+ $ this ->form ->fill (array_merge ($ this -> article ->toArray (), [
45
+ 'is_draft ' => ! $ this -> article ->published_at , // @phpstan-ignore-line
46
+ 'published_at ' => $ this -> article ->published_at , // @phpstan-ignore-line
48
47
]));
49
-
50
- $ this ->article = $ article ;
51
48
}
52
49
53
50
public static function panelMaxWidth (): string
@@ -78,55 +75,61 @@ public function form(Form $form): Form
78
75
->live (onBlur: true )
79
76
->afterStateUpdated (fn ($ state , Forms \Set $ set ) => $ set ('slug ' , Str::slug ($ state ))),
80
77
Forms \Components \Hidden::make ('slug ' ),
78
+ Forms \Components \TextInput::make ('canonical_url ' )
79
+ ->label (__ ('pages/article.form.canonical_url ' ))
80
+ ->helperText (__ ('pages/article.canonical_help ' )),
81
+ Forms \Components \Grid::make ()
82
+ ->schema ([
83
+ Forms \Components \Toggle::make ('is_draft ' )
84
+ ->label (__ ('pages/article.form.draft ' ))
85
+ ->live ()
86
+ ->offIcon ('untitledui-check ' )
87
+ ->onColor ('success ' )
88
+ ->onIcon ('untitledui-pencil-line ' )
89
+ ->helperText (__ ('pages/article.draft_help ' )),
90
+ Forms \Components \DatePicker::make ('published_at ' )
91
+ ->label (__ ('pages/article.form.published_at ' ))
92
+ ->minDate (now ())
93
+ ->prefixIcon ('untitledui-calendar-date ' )
94
+ ->native (false )
95
+ ->visible (fn (Forms \Get $ get ): bool => $ get ('is_draft ' ) === false )
96
+ ->required (fn (Forms \Get $ get ): bool => $ get ('is_draft ' ) === false ),
97
+ ]),
98
+ ])
99
+ ->columnSpan (2 ),
100
+ Forms \Components \Group::make ()
101
+ ->schema ([
102
+ Forms \Components \SpatieMediaLibraryFileUpload::make ('media ' )
103
+ ->collection ('media ' )
104
+ ->label (__ ('pages/article.form.cover ' ))
105
+ ->maxSize (1024 ),
81
106
Forms \Components \Select::make ('tags ' )
82
- ->label ( __ ( ' Tags ' ) )
107
+ ->multiple ( )
83
108
->relationship (
109
+ name: 'tags ' ,
84
110
titleAttribute: 'name ' ,
85
- modifyQueryUsing: fn (Builder $ query ): Builder => $ query ->whereJsonContains ('concerns ' , [ 'post ' ] )
111
+ modifyQueryUsing: fn ($ query ) => $ query ->whereJsonContains ('concerns ' , 'post ' )
86
112
)
87
- ->searchable ()
88
113
->preload ()
89
- ->multiple ()
90
114
->required ()
91
115
->minItems (1 )
92
116
->maxItems (3 ),
117
+ ])
118
+ ->columnSpan (1 ),
119
+ Forms \Components \Group::make ()
120
+ ->schema ([
93
121
Forms \Components \MarkdownEditor::make ('body ' )
94
122
->label (__ ('validation.attributes.content ' ))
95
123
->fileAttachmentsDisk ('public ' )
96
124
->minLength (10 )
97
- ->minHeight ('20.25rem ' )
98
- ->maxHeight ('32.75rem ' )
125
+ ->maxHeight ('20.25rem ' )
99
126
->required (),
100
127
Forms \Components \Placeholder::make ('' )
101
128
->content (fn () => new HtmlString (Blade::render (<<<'Blade'
102
129
<x-torchlight />
103
130
Blade))),
104
131
])
105
- ->columnSpan (2 ),
106
- Forms \Components \Group::make ()
107
- ->schema ([
108
- Forms \Components \SpatieMediaLibraryFileUpload::make ('media ' )
109
- ->collection ('media ' )
110
- ->label (__ ('pages/article.form.cover ' ))
111
- ->maxSize (1024 ),
112
- Forms \Components \Toggle::make ('is_draft ' )
113
- ->label (__ ('pages/article.form.draft ' ))
114
- ->live ()
115
- ->offIcon ('untitledui-check ' )
116
- ->onColor ('success ' )
117
- ->onIcon ('untitledui-pencil-line ' )
118
- ->helperText (__ ('pages/article.draft_help ' )),
119
- Forms \Components \DatePicker::make ('published_at ' )
120
- ->label (__ ('pages/article.form.published_at ' ))
121
- ->minDate (now ())
122
- ->native (false )
123
- ->visible (fn (Forms \Get $ get ): bool => $ get ('is_draft ' ) === false )
124
- ->required (fn (Forms \Get $ get ): bool => $ get ('is_draft ' ) === false ),
125
- Forms \Components \TextInput::make ('canonical_url ' )
126
- ->label (__ ('pages/article.form.canonical_url ' ))
127
- ->helperText (__ ('pages/article.canonical_help ' )),
128
- ])
129
- ->columnSpan (1 ),
132
+ ->columnSpanFull (),
130
133
])
131
134
->columns (3 )
132
135
->statePath ('data ' )
0 commit comments