sort = $item->id; $item->save(); } public static function getByHistoryIds($historyIds = [], $onlyVisible = false) { if(!is_array($historyIds) || count($historyIds) == 0) { return []; } $list = self::whereIn('history_id', $historyIds) ->when($onlyVisible, function ($query) { $query->where('visible', 1); }) ->order(['history_id'=>'asc','sort'=>'asc']) ->select() ->toArray(); $data = []; foreach ($list as $item) { $item['img_list'] = []; if(!empty($item['imgs'])) { $item['img_list'] = array_filter(explode(',', $item['imgs'])); } $data[$item['history_id']][] = $item; } return $data; } public static function countByHistoryId($historyId) { return self::where('history_id', $historyId)->count(); } public static function delByHistoryId($historyId) { return self::where('history_id', $historyId)->delete(); } public static function getByHistoryId($historyId) { if($historyId <= 0) { return []; } return self::where('history_id', $historyId)->order(['sort'=>'asc'])->select()->toArray(); } }