很牛B的写法,数据库,查询,放在一个方法里面,统一过滤、

定义是这样的:

public static function _bind_data($item) {
$item['status_name'] = self::$status[$item['status']];
$item['leader'] = stringToArray($item['leader']);
$item['party'] = stringToArray($item['party']);

$item['leader_names'] = Db::name('office_meeting_boss')->whereIn('user_id', $item['leader'])->column('boss_name');
$item['party_names'] = Db::name('office_meeting_boss')->whereIn('user_id', $item['party'])->column('boss_name');

$item['structure_ids'] = stringToArray($item['structure_ids']);
$item['structure_names'] = Db::name('admin_structure')->whereIn('id', $item['structure_ids'])->column('name');
return $item;
}

 

使用时,是这样用的 :

$models = $model->paginate(input('limit', 10))->each(function($item) {
return self::_bind_data($item);
});

 

posted @ 2021-01-20 18:14  墨晓溪2288  阅读(40)  评论(0编辑  收藏  举报