33namespace Vormkracht10 \Fields \Concerns ;
44
55use Filament \Forms ;
6- use Illuminate \Support \Str ;
7- use Filament \Forms \Components \Grid ;
8- use Illuminate \Support \Facades \Schema ;
96use Filament \Forms \Components \Fieldset ;
7+ use Filament \Forms \Components \Grid ;
108use Filament \Forms \Components \Repeater ;
9+ use Illuminate \Support \Facades \Schema ;
10+ use Illuminate \Support \Str ;
1111
1212trait HasOptions
1313{
@@ -19,17 +19,18 @@ public static function addOptionsToInput(mixed $input, mixed $field): mixed
1919 foreach ($ field ->config ['relations ' ] as $ relation ) {
2020 $ resources = config ('filament-fields.select.resource_options ' );
2121 $ resourceClass = collect ($ resources )->first (function ($ resource ) use ($ relation ) {
22- $ res = new $ resource() ;
22+ $ res = new $ resource ;
2323 $ model = $ res ->getModel ();
24- $ model = new $ model ();
24+ $ model = new $ model ;
25+
2526 return $ model ->getTable () === $ relation ['resource ' ];
2627 });
2728
28- if (!$ resourceClass ) {
29+ if (! $ resourceClass ) {
2930 continue ;
3031 }
3132
32- $ resource = new $ resourceClass() ;
33+ $ resource = new $ resourceClass ;
3334 $ model = $ resource ->getModel ();
3435 $ query = $ model ::query ();
3536
@@ -57,7 +58,7 @@ public static function addOptionsToInput(mixed $input, mixed $field): mixed
5758 $ options [] = $ opts ;
5859 }
5960
60- if (!empty ($ options )) {
61+ if (! empty ($ options )) {
6162 $ options = array_merge (...$ options );
6263 $ input ->options ($ options );
6364 }
@@ -104,8 +105,8 @@ public function optionFormFields(): Fieldset
104105 Forms \Components \KeyValue::make ('config.options ' )
105106 ->label (__ ('Options ' ))
106107 ->columnSpanFull ()
107- ->visible (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'array ' )
108- ->required (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'array ' ),
108+ ->visible (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'array ' )
109+ ->required (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'array ' ),
109110 // Relationship options
110111 Repeater::make ('config.relations ' )
111112 ->label (__ ('Relations ' ))
@@ -122,19 +123,20 @@ public function optionFormFields(): Fieldset
122123 ->afterStateUpdated (function (Forms \Set $ set , ?string $ state ) {
123124 $ resources = config ('filament-fields.select.resource_options ' );
124125 $ resourceClass = collect ($ resources )->first (function ($ resource ) use ($ state ) {
125- $ res = new $ resource() ;
126+ $ res = new $ resource ;
126127 $ model = $ res ->getModel ();
127- $ model = new $ model ();
128+ $ model = new $ model ;
129+
128130 return $ model ->getTable () === $ state ;
129131 });
130132
131- if (!$ resourceClass ) {
133+ if (! $ resourceClass ) {
132134 return ;
133135 }
134136
135- $ resource = new $ resourceClass() ;
137+ $ resource = new $ resourceClass ;
136138 $ model = $ resource ->getModel ();
137- $ model = new $ model() ;
139+ $ model = new $ model ;
138140
139141 // Get all column names from the table
140142 $ columns = Schema::getColumnListing ($ model ->getTable ());
@@ -151,31 +153,31 @@ public function optionFormFields(): Fieldset
151153 $ resources = config ('filament-fields.select.resource_options ' );
152154
153155 return collect ($ resources )->map (function ($ resource ) {
154- $ res = new $ resource() ;
156+ $ res = new $ resource ;
155157 $ model = $ res ->getModel ();
156- $ model = new $ model() ;
158+ $ model = new $ model ;
157159
158160 return [
159- $ model ->getTable () => Str::title ($ model ->getTable ())
161+ $ model ->getTable () => Str::title ($ model ->getTable ()),
160162 ];
161163 })
162164 ->collapse ()
163165 ->toArray ();
164166 })
165167 ->noSearchResultsMessage (__ ('No types found ' ))
166- ->required (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'relationship ' ),
168+ ->required (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'relationship ' ),
167169 Forms \Components \Hidden::make ('relationKey ' )
168170 ->default ('ulid ' )
169171 ->label (__ ('Key ' ))
170- ->required (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'relationship ' ),
172+ ->required (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'relationship ' ),
171173 Forms \Components \Repeater::make ('relationValue_filters ' )
172174 ->label (__ ('Filters ' ))
173- ->visible (fn (Forms \Get $ get ): bool => ! empty ($ get ('resource ' )))
175+ ->visible (fn (Forms \Get $ get ): bool => ! empty ($ get ('resource ' )))
174176 ->schema ([
175177 Forms \Components \Grid::make (3 )
176178 ->schema ([
177179 Forms \Components \Select::make ('column ' )
178- ->options (fn (\Filament \Forms \Get $ get ) => $ get ('../../relationValue_options ' ) ?? [
180+ ->options (fn (\Filament \Forms \Get $ get ) => $ get ('../../relationValue_options ' ) ?? [
179181 'slug ' => __ ('Slug ' ),
180182 'name ' => __ ('Name ' ),
181183 ])
@@ -198,23 +200,24 @@ public function optionFormFields(): Fieldset
198200 $ resource = $ get ('../../resource ' );
199201 $ column = $ get ('column ' );
200202
201- if (!$ resource || !$ column ) {
203+ if (! $ resource || ! $ column ) {
202204 return [];
203205 }
204206
205207 $ resources = config ('filament-fields.select.resource_options ' );
206208 $ resourceClass = collect ($ resources )->first (function ($ r ) use ($ resource ) {
207- $ res = new $ r() ;
209+ $ res = new $ r ;
208210 $ model = $ res ->getModel ();
209- $ model = new $ model ();
211+ $ model = new $ model ;
212+
210213 return $ model ->getTable () === $ resource ;
211214 });
212215
213- if (!$ resourceClass ) {
216+ if (! $ resourceClass ) {
214217 return [];
215218 }
216219
217- $ resource = new $ resourceClass() ;
220+ $ resource = new $ resourceClass ;
218221 $ model = $ resource ->getModel ();
219222
220223 return $ model ::query ()
@@ -224,14 +227,14 @@ public function optionFormFields(): Fieldset
224227 ->toArray ();
225228 })
226229 ->label (__ ('Value ' )),
227- ])
230+ ]),
228231 ])
229232 ->columnSpanFull (),
230233 ]),
231234 ])
232- ->visible (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'relationship ' )
235+ ->visible (fn (Forms \Get $ get ): bool => $ get ('config.optionType ' ) == 'relationship ' )
233236 ->columnSpanFull (),
234237 ]),
235238 ]);
236239 }
237- }
240+ }
0 commit comments