dingo / dingo/api

using item() breaks if relationship doesnt exist collection() doesnt break?

Open
#1,346 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

so if in my transformer i do something like

```
public function includeTestimonials(Entity $item)
{
return $this->collection($item->testimonials, new TestimonialTransformer, true);
}
```
this works even if testimonials is missing

but

```
public function includeShop(Entity $item)
{
if ( $item->shop )
return $this->item($item->shop, new ShopTransformer, true);
}
```

i have to add in an if check otherwise this gives me an error shop entity expected null given? i dont want to be adding lots of if statements..

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.