'desc']; protected function initController(Request $request): void { $this->model = new AttachmentModel(); } public function del(Request $request): Response { $response = $this->initializeBackend($request); if ($response !== null) return $response; $where = []; $dataLimitAdminIds = $this->getDataLimitAdminIds(); if ($dataLimitAdminIds) { $where[] = [$this->dataLimitField, 'in', $dataLimitAdminIds]; } $ids = $request->post('ids', $request->get('ids', [])); $ids = is_array($ids) ? $ids : []; $where[] = [$this->model->getPk(), 'in', $ids]; $data = $this->model->where($where)->select(); $count = 0; try { foreach ($data as $v) { $count += $v->delete(); } } catch (\Throwable $e) { return $this->error(__('%d records and files have been deleted', [$count]) . $e->getMessage()); } return $count ? $this->success(__('%d records and files have been deleted', [$count])) : $this->error(__('No rows were deleted')); } }