![]() ![]() What I got: a collection with only 1 element. What I expected: when a price is requested for a specific customer_type I want to get the scoped price for that specific customer_type as a nested element. Before adding such a relationship to a schema, you need to consider whether the relationship is better. A polymorphic relationship is a relationship that can contain multiple different resource types. ![]() In my case a have a belongsToMany relationship between materials and customer_types, the pivot table contains the material price for specific customer types, therefore there are as many records (prices) in the pivot table as customer_types are. Laravel JSON:API contains a MorphToMany relationship field, that allows you to add polymorphic to-many relationships to your resource schemas. I faced the exactly same issue, let me show you how I managed it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |