laravel-splade
laravel-splade copied to clipboard
How to get relation data in form
How i can get attributes from relation into Spade Form?
This still didn't work for me. It would be great if @pascalbaljet gave an insight on this, otherwise I am stuck.
make sure by dd relation data link with your Model ?
make sure by dd relation data link with your Model ?
Yes, the relation is there. Even in the view, I am able to render the relation nicely but the values don't show in the inputs
Please if possible, to share your code snippet of method and view? I mean paste here
Alright, here we go.
The above picture shows a function for editing a customer. It calls a modal from the view
The above picture is a view in a modal that gets opened by the function in the very first picture. It is in this modal view where the values don't show up
The above picture is a a customer model
i guess you need a foreach loop to fetch data from get
That's actually not the reason because I just changed that to see what data I would get in a collection. Look at the working code from the pictures below.
The above picture is the working code. Let me show you what happens
The above is a data table displaying all contacts (currently there is only one contact). If click on the edit icon from the ACTIONS column, i get the following modal
You see how the phone number is missing but the rest of the data is showing?
Which version are you using? even i check by implementing modal, perfectly work. and one more thing make sure mobile field exist typically must be in fillable of Phone Model
Laravel version 9.19 Laravel-Splade version 0.6.11
And here is the phone model
In edit form that you are using in modal place this code {{$customer->phone->mobile}} or {{$customer->phone}} after the
That one shows the phone like it is supposed to.
I have solved it by casting values in the :default property like in the picture below
It's working, but I feel like it's a hack. For now I get what I wanted.
It has been fixed in v0.6.12. Nested relationships, like the example below, now work:
<x-splade-form :default="$project">
<x-splade-input name="name" label="Name" />
<x-splade-input name="organization.address.city" label="City" />
</x-splade-form>
How to set default values on <x-splade-select
using the relationship