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
toeknee
toeknee2y ago
It sounds like you want a relationship manager?
fairygamer
fairygamerOP2y ago
not really. Like i dont want to update any record. All I need is I want to display the text from the relationship table
toeknee
toeknee2y ago
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
fairygamer
fairygamerOP2y ago
I tried but it shows empty
krekas
krekas2y ago
maybe wrong fields you are using? show some code
toeknee
toeknee2y ago
IF you tried and it's empty, you need to check your relationship method.
fairygamer
fairygamerOP2y ago
in list it getting the record but not in the form
fairygamer
fairygamerOP2y ago
Lead Resource file
MailAssigned Model
toeknee
toeknee2y ago
That looks good, are you saying mail.subject has no value?
fairygamer
fairygamerOP2y ago
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
toeknee
toeknee2y ago
So then your relationship isn't working correctly Try passing in the local and the foreign key with the relationship
krekas
krekas2y ago
How migration looks?
fairygamer
fairygamerOP2y ago
return $this->belongsTo(Mail::class, 'mail_id', 'id'); still empty
fairygamer
fairygamerOP2y ago
yellow color -> local table, orange color -> foreign table
fairygamer
fairygamerOP2y ago
On edit popup its not showing
fairygamer
fairygamerOP2y ago
Migration is looks correct even the foreign key are mapped correctly
krekas
krekas2y ago
check in db if value is there
fairygamer
fairygamerOP2y ago
LOL... it does
krekas
krekas2y ago
doesn't look like
fairygamer
fairygamerOP2y ago
Foreign table
fairygamer
fairygamerOP2y ago
Listing table
toeknee
toeknee2y ago
So to confirm, it's working fine in the table? But not in the form correct? Try: Textarea::make('mail') ->relationship('mail', 'body'),
Dan Harrin
Dan Harrin2y ago
this isnt a thing you would wrap the Textarea in a group or another layout component
toeknee
toeknee2y ago
How do you mean, do relationships only work on selects?
Dan Harrin
Dan Harrin2y ago
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
toeknee
toeknee2y ago
My bad, thanks Dan
fairygamer
fairygamerOP2y ago
Is there any component to only diplay as text rather than input box?
toeknee
toeknee2y ago
Placeholder
fairygamer
fairygamerOP2y ago
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
Want results from more Discord servers?
Add your server