laravel-splade icon indicating copy to clipboard operation
laravel-splade copied to clipboard

How to get relation data in form

Open syedahnb opened this issue 1 year ago • 1 comments

image image How i can get attributes from relation into Spade Form?

syedahnb avatar Oct 15 '22 19:10 syedahnb

image

syedahnb avatar Oct 27 '22 10:10 syedahnb

image

This still didn't work for me. It would be great if @pascalbaljet gave an insight on this, otherwise I am stuck.

MotionPhix avatar Oct 28 '22 15:10 MotionPhix

make sure by dd relation data link with your Model ?

syedahnb avatar Oct 28 '22 15:10 syedahnb

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

MotionPhix avatar Oct 28 '22 15:10 MotionPhix

Please if possible, to share your code snippet of method and view? I mean paste here

syedahnb avatar Oct 28 '22 15:10 syedahnb

Alright, here we go.

Screenshot_20221028_061417

The above picture shows a function for editing a customer. It calls a modal from the view

Screenshot_20221028_061520

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

Screenshot_20221028_061614

The above picture is a a customer model

MotionPhix avatar Oct 28 '22 16:10 MotionPhix

i guess you need a foreach loop to fetch data from get

syedahnb avatar Oct 28 '22 16:10 syedahnb

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.

Screenshot 2022-10-28 184629

The above picture is the working code. Let me show you what happens

Screenshot 2022-10-28 184726

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

Screenshot 2022-10-28 184814

You see how the phone number is missing but the rest of the data is showing?

MotionPhix avatar Oct 28 '22 16:10 MotionPhix

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

syedahnb avatar Oct 28 '22 17:10 syedahnb

Laravel version 9.19 Laravel-Splade version 0.6.11

And here is the phone model

Screenshot 2022-10-28 181700

MotionPhix avatar Oct 28 '22 17:10 MotionPhix

In edit form that you are using in modal place this code {{$customer->phone->mobile}} or {{$customer->phone}} after the opening tag and what is the output?

syedahnb avatar Oct 28 '22 17:10 syedahnb

That one shows the phone like it is supposed to.

Screenshot 2022-10-28 194027

MotionPhix avatar Oct 28 '22 17:10 MotionPhix

I have solved it by casting values in the :default property like in the picture below

Screenshot 2022-10-28 203438

It's working, but I feel like it's a hack. For now I get what I wanted.

Screenshot_20221028_083720

MotionPhix avatar Oct 28 '22 18:10 MotionPhix

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>

pascalbaljet avatar Oct 31 '22 09:10 pascalbaljet