我在使用 Fractal 库时遇到问题。我正在使用 Spatie\laravel-fractal 库,它只是 League\fractal 的包装器。所以...
我想返回一个空对象而不是一个空数组。
public function includeDocumentType(Question $question)
{
return $question->documentType
? $this->item($question->documentType, new DocumentTypeTransformer)
: $this->null();
}
$this->null()
总是[]
一代又一代回来,我想回来{}
。Tbh 我想要有 2 个函数,比如$this->nullItem()
和$this->nullCollection()
。
有谁知道这个问题的解决方案是什么?