Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fracture Transform throws boolean given

I am using a Transformer in my Laravel project. When I don't include an other object in the Transformer there isn't any problem but when I include the Customer object I get the following error:

Argument 1 passed to App\Transformers\CustomerTransformer::transform() must be an instance of App\Models\Customer, boolean given, called in /home/vagrant/Code/project/vendor/league/fractal/src/Scope.php on line 365 and defined

When I printed the object from Scope.php there weren't any booleans in it. What could be the problem? (The code crashes after Review #298.

enter image description here

How I call the code:

$reviews = $this->review->paginate();
$transformer = new ReviewTransformer();
$with = $request->get('with', null);
if($with) {
    $with = explode(';', $with);
    $transformer->parseIncludes($with);
}
return $this->response->paginator($reviews, $transformer); 
like image 486
Bart Bergmans Avatar asked Feb 07 '23 03:02

Bart Bergmans


1 Answers

Fixed the problem, I'm an idiot..

I had the following include in my Transformer class:

public function includeCustomer(Review $review) 
{
    $customer = $review->customer;
    return $this->collection($customer, new CustomerTransformer);
}

The problem is that $customer is an Item an not a Collection. I had to change this->collection to this->item.

like image 102
Bart Bergmans Avatar answered Feb 18 '23 21:02

Bart Bergmans