Value of field ins null
In my OrderItem I have this:
The model OrderItem has this field:
In the database the user_id field has a value.
However the above TextInput return null. How can I print the name of the related user?
When I do
user.name
I get null
21 Replies
orderItem.user.name ?
or however you name your relation
why not a select?
Because it is added automatically by the model. And the field is disabled by default. It should only show who created the item
the field can be
->disabled()
and you can use $operation
to show it only in the edit/view page
Ok, but when I do:
I can't see the name either (in edit mode)
->relationship('user', 'name')
I had this before. But then it shows the same user in each record.
Maybe something wrong in the relationship?
probably
The OrderItem belongs to a User.
@Leandro Ferreira Can it be it uses the User relationsship of the Order in stead of the OrderItem?
yes 🤷♂️
How can I rule it out ?
Because in the queries I only see:
"select * from
users
where id
= 1 limit 1`"what does it mean?
it means it selects the user where id is 1. But it doesn't rule out if it picks the relation of the user->order or order-item -> user
sorry, I don't understand your question.. anyway, you should check your relationship
Posts on the demo site has this relationship
https://demo.filamentphp.com/blog/posts
Maybe this can help you
My main issue is the following:
I have an Items Repeater for OrderItems.
What I want is that when I add a new Item. The new OrderItem should be prefilled and saved with the current logged in user. When the order is saved the existing OrderItems should not be modified. The created by field of the other items should not be changed.
Now In my situation all OrderITems are being related to the current user.
Just dont pass the related columnn and have an observer fill it?
But I need to show it on each OrderItem. I have just changed manually all user_id's in the database in the OrderItem table (for testing) now when I save the order from the UI all user_id's are overwritten and have the same user Id.
When its null can't you get the user id via auth() ?
Yes I can but my problem is that it updates all order items in stead of the order item added.
Show the repeater code
I found the error:
This would update all records before saving. Ouch