F
Filamentβ€’17mo ago
Husky110

Display Relationshipvalue in View-Form on Resource-Modal

Hi - Since Discord decides to bug out on the search-function and scrolling the result and I can't find it anywhere, could someone please point me in the right direction? I got a Resource and wanna do a quick view-action, so I build up the form()-method like this:
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('myrelation.worker')
->label('Queue'),
Forms\Components\TextInput::make('myrelation.jobkey')
->label('Job'),
Forms\Components\Textarea::make('message')
->label('Fehlernachricht'),
Forms\Components\Textarea::make('job_data')
->label('Payload'),
Forms\Components\Textarea::make('trace')
->label('Trace')
->columnSpan(2),

]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('myrelation.worker')
->label('Queue'),
Forms\Components\TextInput::make('myrelation.jobkey')
->label('Job'),
Forms\Components\Textarea::make('message')
->label('Fehlernachricht'),
Forms\Components\Textarea::make('job_data')
->label('Payload'),
Forms\Components\Textarea::make('trace')
->label('Trace')
->columnSpan(2),

]);
}
The fields on the record itself work fine, but the RelationShip-Fields on "myrelation" are empty. I found how to fix that on selects, but not on TextInputs. How can I fill those fields with their respected values? (I don't think that I have a typo on the notions.)
Solution:
->formatStateUsing(fn($record) => $record->myrelation->worker) ?...
Jump to solution
5 Replies
toeknee
toekneeβ€’17mo ago
is worker a data set or a string?
Husky110
Husky110OPβ€’17mo ago
both worker and jobkey are strings
Solution
toeknee
toekneeβ€’17mo ago
->formatStateUsing(fn($record) => $record->myrelation->worker) ?
Husky110
Husky110OPβ€’17mo ago
Thanks - I thought it was something easy. Just didn't find it! πŸ™‚
toeknee
toekneeβ€’17mo ago
Ahh no problem! I still get confused sometimes. I even had to refer to the docs just then for a mount action using method I was missing πŸ™‚
Want results from more Discord servers?
Add your server