swisnl / json-api-client

A PHP package for mapping remote {json:api} resources to Eloquent like models and collections.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infinite loop toArray()

DylandeWit opened this issue · comments

Context:
Monkey has a Banana. Banana has a Monkey.
Get request on Monkey with Banana included.
Monkey also gets loaded in Banana because of relationships but Monkey is not included with Banana.

Problem:
When you call toArray on Monkey's Banana and Banana calls toArray on Monkey, you end up with an unintended infinite loop.

Dirty fix:
$this->banana->setRelation('monkey', new JenssegersItem());

Recommended fix:
$this->banana->excludeRelation('monkey');

Have not heard of people having this issue anymore. Should you still see this issue happening, please reopen this issue.