在运行查询生成器并对数据进行分页时,我在返回数据时遇到了一些小问题
我在想,在我分页数据之前,是否有人知道我如何删除Null结果。
// So Before I hit this
$return = $tld->paginate($request->get('limit'))->toArray();这就是我分页后的问题
array:12 [
"current_page" => 1
"data" => array:12 [
0 => null
1 => array:3 [我需要摆脱那些零值,我知道如何在我分页之后去做,但是我想在我分页之前把它们处理掉。
我希望你们中的一些人能帮助我。
为$tld添加了这个额外的逻辑
private function newest(Request $request)
{
$this->validate($request, [
'timescale' => [
'required',
Rule::in(['today', 'this_week', 'this_month', 'all_time'])
]
]);
$tld = TimelineItem::where('timeline_items.created_at', '>', $this->timescaleToHours($request->get('timescale')));
if ($request->search_content) {
$tld = $this->searchContent($tld, $request->search_content, 0.4);
} else {
$tld = $tld->orderBy('timeline_items.created_at', 'DESC');
}
if ($request->types) {
$tld = $this->filters($tld, $request->types);
}
if ($request->tags) {
$tld = $this->tags($tld, $request->tags);
}
return $tld;
}发布于 2020-07-03 11:11:38
您可以使用filter()删除null。Laravel收集过滤器()
$response = $tld->paginate($request->get('limit'))->toArray();
$response['data'] = collect($response['data'])->filter()->toArray();
return $response;https://stackoverflow.com/questions/62713810
复制相似问题