在分页对象数据上追加属性
使用框架自带的分页类,并不支持直接追加属性,但是想追加,只是简单赋值是不行的
1.查询结果集:$list = User::where('status',1)->paginate(1);
2.借助collect对象,组装数据:
$custom = collect(['flag' => $flag]);
3.合并数据:
$list = $custom->merge($list);
4.最后得到包含我们自定义数据 flag
{
"flag": true,
"current_page": 1,
"data": [
{
"id": 5,
"store_id": 69,
"salary_setting_id": 7,
}
],
"first_page_url": "...",
"from": 1,
"last_page": 1,
"last_page_url": "...",
"next_page_url": null,
"path": "...",
"per_page": 5,
"prev_page_url": null,
"to": 1,
"total": 1
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: