我刚开始玩laravel,当我尝试从数据库中获取值时,它很好。但是当我试图返回值时,它只是空的。这是代码:
public function index()
{
$collection = [];
Leg::chunk(200, function ($data) {
foreach ($data as $val) {
$collection[] = [
'fixture_id' => $val->fixture_id,
'ops_leg_id' => $val->ops_leg_id,
'designator' => $val->designator,
'operator' => $val->operator,
'flight_number' => $val->flight_number,
'dep_airport' => $val->dep_airport,
'arr_airport' => $val->arr_airport,
'ac_registration' => $val->ac_registration,
'ac_code' => $val->ac_code,
'sta_at' => $val->sta_at,
'std_at' => $val->std_at,
'ata_at' => $val->ata_at,
'atd_at' => $val->atd_at,
'deleted' => $val->deleted
];
}
});
return array($collection);
}
编辑:我的网页输出只是 [[]]
答案 0 :(得分:1)
内联函数不返回任何内容
public function index()
{
Leg::chunk(200, function ($data) {
$collection = [];
foreach ($data as $val) {
$collection[] = [
'fixture_id' => $val->fixture_id,
'ops_leg_id' => $val->ops_leg_id,
'designator' => $val->designator,
'operator' => $val->operator,
'flight_number' => $val->flight_number,
'dep_airport' => $val->dep_airport,
'arr_airport' => $val->arr_airport,
'ac_registration' => $val->ac_registration,
'ac_code' => $val->ac_code,
'sta_at' => $val->sta_at,
'std_at' => $val->std_at,
'ata_at' => $val->ata_at,
'atd_at' => $val->atd_at,
'deleted' => $val->deleted
];
}
return array($collection);
});
}