How to pass relationship value to the TextInput
I have a relationship field where I want to display the value in the form.
Eg: Mail Assigned Table and the Mails Table. Im listing the records from the Assigned table when I click edit, I want to display the email content from the Mail table. How to achieve this?
30 Replies
It sounds like you want a relationship manager?
not really. Like i dont want to update any record. All I need is I want to display the text from the relationship table
So it’s from a single relationship? Just call it with the dot syntax?
myrelationship.content
In a field unless I’m missing what you want
I tried but it shows empty
maybe wrong fields you are using? show some code
IF you tried and it's empty, you need to check your relationship method.
in list it getting the record but not in the form
That looks good, are you saying mail.subject has no value?
I tried both mail.subject and mail.body in the form section and Im getting only empty string. But in table function it showing the values
So then your relationship isn't working correctly
Try passing in the local and the foreign key with the relationship
How migration looks?
return $this->belongsTo(Mail::class, 'mail_id', 'id');
still empty
yellow color -> local table, orange color -> foreign table
On edit popup its not showing
Migration is looks correct even the foreign key are mapped correctly
check in db if value is there
LOL... it does
doesn't look like
Foreign table
Listing table
So to confirm, it's working fine in the table? But not in the form correct?
Try:
Textarea::make('mail')
->relationship('mail', 'body'),
this isnt a thing
you would wrap the Textarea in a group or another layout component
How do you mean, do relationships only work on selects?
not quite
selects never write to a relationship table
they save a foreign key on the current table
using a layout component, everything inside is teleported to a related table
My bad, thanks Dan
Is there any component to only diplay as text rather than input box?
Placeholder
thanks. as mentioned by Dan, I created a layout with relationship and then calling the field works as expected.
Hence Im closing this thread. Thank you so much for the help @toeknee_iom @Dan Harrin