![]() ![]() Map each resource identifier to the correct sub-relationship. When modifying the relationship, this means we can Media relationship - the sub-relationships return audio, images and Sub-relationship per JSON:API resource type. In addition, a modifiable MorphToMany relationship must have only one Then you can only use modifiable to-many JSON:API relationship fields: i.e.Īll to-many fields except HasManyThrough. However, if you require the relationship to be modifiable, You can use any JSON:API relationship field for the sub-relationships, including Use LaravelJsonApi \Eloquent \Fields \Relations \BelongsToMany use LaravelJsonApi \Eloquent \Fields \Relations \MorphToMany MorphToMany :: make ( 'media', ) For example, if it was going to show a list of postsĪnd only use their related images, it can use the following request: The advantage with this approach is the client can now choose to only include Namespace App \Models use Illuminate \Database \Eloquent \Model use Illuminate \Database \Eloquent \Relations \BelongsToMany class Post extends Model ![]() We will use a Post model, that hasĪudio, images and videos relationships. Throughout this chapter we will use the following scenario to demonstrate howĪ polymorphic relationship can work. This chapter describes how to add it to your schema and other implementation ![]() If you decide that a polymorphic to-many relationship is your preferred approach, Which approach best matches your use case. ThisĬhapter describes the pros and cons of each approach, so that you can decide Whether you expose each related resource type in a separate relationship. Relationship is better added as a single polymorphic to-many relationship, or Polymorphic relationship is a relationship that can contain multiple differentīefore adding such a relationship to a schema, you need to consider whether the To add polymorphic to-many relationships to your resource schemas. Laravel JSON:API contains a MorphToMany relationship field, that allows you ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |