1616use Filament \Forms \Form ;
1717use Filament \Notifications \Notification ;
1818use Illuminate \Contracts \View \View ;
19- use Illuminate \Database \Eloquent \Builder ;
2019use Illuminate \Support \Facades \Auth ;
2120use Illuminate \Support \Facades \Blade ;
2221use Illuminate \Support \HtmlString ;
@@ -37,17 +36,15 @@ final class ArticleForm extends SlideOverComponent implements HasForms
3736
3837 public function mount (?int $ articleId = null ): void
3938 {
40- /** @var Article $article */
41- $ article = $ articleId
39+ // @phpstan-ignore-next-line
40+ $ this -> article = $ articleId
4241 ? Article::query ()->findOrFail ($ articleId )
4342 : new Article ;
4443
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
4847 ]));
49-
50- $ this ->article = $ article ;
5148 }
5249
5350 public static function panelMaxWidth (): string
@@ -78,55 +75,61 @@ public function form(Form $form): Form
7875 ->live (onBlur: true )
7976 ->afterStateUpdated (fn ($ state , Forms \Set $ set ) => $ set ('slug ' , Str::slug ($ state ))),
8077 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 ),
81106 Forms \Components \Select::make ('tags ' )
82- ->label ( __ ( ' Tags ' ) )
107+ ->multiple ( )
83108 ->relationship (
109+ name: 'tags ' ,
84110 titleAttribute: 'name ' ,
85- modifyQueryUsing: fn (Builder $ query ): Builder => $ query ->whereJsonContains ('concerns ' , [ 'post ' ] )
111+ modifyQueryUsing: fn ($ query ) => $ query ->whereJsonContains ('concerns ' , 'post ' )
86112 )
87- ->searchable ()
88113 ->preload ()
89- ->multiple ()
90114 ->required ()
91115 ->minItems (1 )
92116 ->maxItems (3 ),
117+ ])
118+ ->columnSpan (1 ),
119+ Forms \Components \Group::make ()
120+ ->schema ([
93121 Forms \Components \MarkdownEditor::make ('body ' )
94122 ->label (__ ('validation.attributes.content ' ))
95123 ->fileAttachmentsDisk ('public ' )
96124 ->minLength (10 )
97- ->minHeight ('20.25rem ' )
98- ->maxHeight ('32.75rem ' )
125+ ->maxHeight ('20.25rem ' )
99126 ->required (),
100127 Forms \Components \Placeholder::make ('' )
101128 ->content (fn () => new HtmlString (Blade::render (<<<'Blade'
102129 <x-torchlight />
103130 Blade))),
104131 ])
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 (),
130133 ])
131134 ->columns (3 )
132135 ->statePath ('data ' )
0 commit comments