_service = 'lms'; $this->_module = 'articles_bank'; $this->_viewname = 'articlesbank'; $this->_title = 'Article Bank'; $this->_base_url = '/articlebank'; } protected function get_list_fields() { return [ 'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']], 'title' => ['title' => 'Title', 'type' => 'text'], 'description' => ['title' => 'Description', 'type' => 'text'], 'status' => ['title' => 'Status', 'type' => 'select'] ]; } protected function get_form_fields($type, $values) { return [ 'title' => ['title' => 'Title', 'type' => 'text', 'required' => true], 'description' => ['title' => 'Description', 'type' => 'text', 'required' => true], 'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']], 'contents' => ['title' => 'Content', 'type' => 'mapping', 'fullwidth' => true], 'icon' => ['title' => 'Icon', 'type' => 'file', 'required' => true] ]; } protected function _beforesave($type, $request) { $data = $request->except('_token'); if ($request->file('icon')) { $data['icon'] = $this->_uploadMedia($request->file('icon'), 'icon', 'lms_cources'); } foreach ($data['contents']['tempcontent'] as $tempcontent) { if (!is_file($tempcontent)) { $data['contents']['content'][] = $tempcontent; } } $files = $request->file('contents.tempcontent'); if ($files) { foreach ($files as $file) { $path = $this->_uploadMedia($file, 'lms_articlebank'); $data['contents']['content'][] = $path; } } unset($data['contents']['tempcontent']); return $data; } protected function _uploadMedia($file, $name = 'image', $folder = 'image') { $path = ''; try { if ($file) { $path = $file->store($folder, 's3'); $path = env('AWS_URL') . '/' . $path; } } catch (AwsException $e) { Log::debug($e->getMessage()); } return $path; } }