Repeater fields are missing on view/edit
I have a repeater field that I add multiple values to but when I then view the record or try to edit it, only the first one in shown.
Here is the code for my repeater:
This is for a simple resource so I don't know if there is something I should be doing to get all of the values I created the record with?
In terms of my database, this Wizard Step is for a group of products and I am looking to add many products. I have a
group products
table, stock products
table and a group stock products
table.
Not entirely sure what is missing at this point of where I should look in the docs.27 Replies
(apologies for the formatting in advance)
When I view a group of products, the 2nd step of the wizard should show all of the stock items. At the moment, it only displays one.
what is the relationship return
I don't know what you mean by
relationship return
You have a relationshup called stockProducts
ah sorry yes
the function stockProducts has a return
one second
it should return them all?
It should, can you run:
->formatStateUsing(fn($state) => dd($state))
to the repeater, What does it show
Let me have a look
I assume you mean on the wizard step for this? If so,
dd
does not fire. If there is somewhere else I am supposed to add the repeater, this is likely why it isn't working as I thought it was only necessary on creation.I mean on:
yeah that is what I did.
That should die on that repeater as it allows formatting the state for population. But it is possible it's not used on the repeater but it is defined in the namespace
I was trying to view a record, let me try and create one
What if you do:
Essentially you need to dump the relationship on the repeater to see what it has returned
interesting,
dd
does not fire on creation either.. let me try your 2nd example.
that fires when I click to add a new product or try to edit an exsiting one:
This group should have 2 products howeverThat is strange, I am unsure why you are getting that, hasMany should be good
I will try and see if a non-simple resource presents the same problem and if not, maybe move to that.
what about the bom_stock_products table? What was stored?
it was storing it correctly, 2 rows, both with the same group id and different stock ids
can you show it please?
The DB rows?
yep
sure, one moment as I done a fresh migration, working on a couple of bits this morning.
So for context, I just created 2 stock products, then a group product (bom) with the 2 stock products.
I grabbed a screen shot of them all for you which I will now upload.
Hopefully the order persists
As you can see it seems like it is all working as expected with the exception of the view. I did just notice however that the view returns only the last record.
add an id pk in the bom_stock_products table
I will give that a try.
yes that worked, what a silly mistake 🤦♂️ - thought it would be fine as it was.
Thank you Leandro!