Bar*_*ans 3 php laravel dingo-api
我在Laravel项目中使用的是Transformer。当我在Transformer中不包含其他对象时,没有任何问题,但是当我包含该Customer对象时,出现以下错误:
传递给App \ Transformers \ CustomerTransformer :: transform()的参数1必须是App \ Models \ Customer的实例(给定布尔值),在/home/vagrant/Code/project/vendor/league/fractal/src/Scope.php中调用在第365行并定义
当我从中打印对象时,Scope.php其中没有任何布尔值。可能是什么问题呢?(代码在Review之后崩溃#298。
我如何调用代码:
$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);
Run Code Online (Sandbox Code Playgroud)
解决了这个问题,我是个白痴。
我的Transformer类中包含以下内容:
public function includeCustomer(Review $review)
{
$customer = $review->customer;
return $this->collection($customer, new CustomerTransformer);
}
Run Code Online (Sandbox Code Playgroud)
问题是那$customer是一个项目而不是一个集合。我不得不this->collection改为this->item。
| 归档时间: |
|
| 查看次数: |
394 次 |
| 最近记录: |