dingo/api的response->collection方法是有什么特殊的设置么?
下面的代码,当$domains查数据库返回数据时,得到的body是空的,但是http_code是200。
问题截图:
Laravel 5.6
dingo dev-master
jwt-auth dev-master
PHP 7.1
Controller.php
``
public function GetByMethod($method,$data)
{
$transformer = [
'domain_id' => 'id',
'domain_name' => 'name',
'master_server' => 'master',
'last_check_time' => 'last_check',
'zone_type' => 'type',
'maintenance_account' => 'account'
];
if(array_key_exists($method,$transformer))
{
$domains = Domain::where($transformer[$method],'=',$data)->get();
if (count($domains))
{
$this->response->collection($domains,new DomainTransformer());
}
else
{
$this->response->errorNotFound();
}
}
else
{
$this->response->errorBadRequest('Invalid query method');
}
}
``
DomainTransformer.php
``
class DomainTransformer extends TransformerAbstract
{
public function transform(Domain $domain)
{
return [
'domain_id' => $domain['id'],
'domain_name' => $domain['name'],
'master_server' => $domain['master'],
'last_check_time' => $domain['last_check'],
'zone_type' => $domain['type'],
'maintenance_account' => $domain['account']
];
}
}
``