Skip to content
Advertisement

Laravel withPivot is not returning pivot extra fields

I have Two models called Product and Store In Store model i have this codes:

JavaScript

In Product model i have this code:

JavaScript

And i have a resource for Product with this code:

JavaScript

So when i use $store = AppModelsStore::find($store_id); it should return a pivot in my store relation but it is not doing this. Please help me to solve it

Thank you in advance

Advertisement

Answer

if you want to load the pivot when you retrieve the store, you have to eager load it.

in Store.php Model:

JavaScript

it seems this lines:

JavaScript

is returning Store Model and should be change :

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement