You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class OrganisationTransformer extends Transformer
{
protected $relations = [
'contact',
'AnotherRelation' => AnotherRelationTransformer::class,
];
protected $load = [];
public function transform(Organisation $organisation)
{
return [
'id' => (int) $organisation->id,
'name' => (string) $organisation->name,
];
}
public function includeContact(Organisation $organisation)
{
return Transformation::make($organisation, OrganisationContactTransformer::class)->with('mailingAddress')->transform();
}
}
Get request to /organisation?with=contact works
Get request to /model?with=organisation works
Get request to /model?with=organisation.AnotherRelation works
Get request to /model?with=organisation.contact doesnt work
Any ideas why with=organisation.contact relation is not working
The text was updated successfully, but these errors were encountered:
Its because contact is not a real relation, Organisation has contact fields, but those are normally not needed. so those would only be returned when needed (with=contact)
The errors message is:
{
"status":422,
"success":false,
"error":{
"code":"relation_not_found",
"message":null
}
}
Illuminate\Database\Eloquent\RelationNotFoundException: Call to undefined relationship [contact] on model [App\Organisation].
Hello,
I have Transformers:
and
Get request to
/organisation?with=contact
worksGet request to
/model?with=organisation
worksGet request to
/model?with=organisation.AnotherRelation
worksGet request to
/model?with=organisation.contact
doesnt workAny ideas why
with=organisation.contact
relation is not workingThe text was updated successfully, but these errors were encountered: