Accessing accessor trough a relationship
Hi, i got a problem and i couldnt find the answer on the net.
in my Invoice resource i have a table column like this
in the invoice model i have a relationship like this
And then in my LineItem model i have this
the additionalitemproperties is a relationship to a model that has many records beloning to one lineitem
i cant figure it out thanks for the help
Solution:Jump to solution
I fixed it using the $state property. It was too much work so just went trough the tables manually
7 Replies
hey .. since you're using hasMany .. from which of the many should the total_vat be taken?
Hey thanks for to reply.
Initially its a check for the additionalLineItems model.
So the additionalLineItems model has multiple rows connected to a line item.
This is how its stored. In additionalLineItems.
Total=100
TotalVat=50
And in my invoice resource, that has a lineitem. I want to display a column in the table giving me the totalVat.
Its a bit hard to explain but i hope im explaining it good
I could provide screenshots if needed
mmh i really don't get it 🙂
but for my understanding .. if you use hasMany .. and want to use it in a column .. you have either decide which of the many like ->latestOfMany() or you have to aggregate ->hasOne(LineItem::class)->ofMany('total_vat', 'sum')
Alright thank you for your answer. But how would i make a textcolumn from a eloquentaccessor. Maybe that is easier to explain. I just want to use a field that is filtered thats why im using a accessor
what exactly do you want to filter ?
if you don't use s.th. like latestOfMany .. eloquent load the data using different select .. if you want to filter or sort .. u need a join on the tables
Solution
I fixed it using the $state property. It was too much work so just went trough the tables manually
Thanks anyway💪