-
Notifications
You must be signed in to change notification settings - Fork 106
Description
not really an issue but, currently I have:
Articles (Schema):
'title' => string,
'slug' => string,
'content' => string,
'user_id' => foreignId,
Images (Schema):
'url' => string,
'imageable_id' => string,
'imageable_type' => string,
OR
morphs(imageable),
Article (Class):
user = () => {
return $this->belongsTo(User::Class);
}
images = () => {
return $this->morphMany(Image::class, 'imageable');
}
Image (Class):
imageable = () => {
return $this->morphTo('imageable');
}
and im testing, on php unit;
$this->jsonApi()->withData([ 'type' => 'articles', 'attributes' => Article::factory()->raw(), 'relationships' => [ 'users' => [ 'data' => [ 'type' => 'users', 'id' => User::factory()->create()->getRouteKey(), ] ], ], ])->post(route('api.v1.articles.create));
this works; but is there a way to include the images relationship within the same request... because the only thing Im thinking about right now is that the Images table can only be filled via the images routes:
$this->jsonApi()->withData([ 'type' => 'images', 'attributes' => Image::factory()->raw(), 'relationships' => [ 'imageable' => [ 'data' => [ 'type' => 'articles', 'id' => Article::factory()->create()->getRouteKey(), ] ], ], ])->post(route('api.v1.images.create));