@@ -288,7 +288,23 @@ protected function selectableValuesFormFields(string $type, string $label, strin
288288 Select::make ('relationKey ' )
289289 ->label (__ ('Key Column ' ))
290290 ->helperText (__ ('The column to use as the unique identifier/value for each option ' ))
291- ->options (fn (Get $ get ) => $ get ('relationKey_options ' ) ?? [])
291+ ->options (function (Get $ get ) {
292+ $ resource = $ get ('resource ' );
293+ if (! $ resource ) {
294+ return [];
295+ }
296+
297+ $ model = static ::resolveResourceModel ($ resource );
298+ if (! $ model ) {
299+ return [];
300+ }
301+
302+ $ columns = Schema::getColumnListing ($ model ->getTable ());
303+
304+ return collect ($ columns )->mapWithKeys (function ($ column ) {
305+ return [$ column => Str::title ($ column )];
306+ })->toArray ();
307+ })
292308 ->searchable ()
293309 ->visible (fn (Get $ get ): bool => ! empty ($ get ('resource ' )))
294310 ->required (
@@ -298,7 +314,23 @@ protected function selectableValuesFormFields(string $type, string $label, strin
298314 Select::make ('relationValue ' )
299315 ->label (__ ('Display Column ' ))
300316 ->helperText (__ ('The column to use as the display text/label for each option ' ))
301- ->options (fn (Get $ get ) => $ get ('relationValue_options ' ) ?? [])
317+ ->options (function (Get $ get ) {
318+ $ resource = $ get ('resource ' );
319+ if (! $ resource ) {
320+ return [];
321+ }
322+
323+ $ model = static ::resolveResourceModel ($ resource );
324+ if (! $ model ) {
325+ return [];
326+ }
327+
328+ $ columns = Schema::getColumnListing ($ model ->getTable ());
329+
330+ return collect ($ columns )->mapWithKeys (function ($ column ) {
331+ return [$ column => Str::title ($ column )];
332+ })->toArray ();
333+ })
302334 ->searchable ()
303335 ->visible (fn (Get $ get ): bool => ! empty ($ get ('resource ' )))
304336 ->required (fn (Get $ get ): bool => ! empty ($ get ('resource ' ))),
0 commit comments