/** * Execute the job. * * @return void */ public function handle() { //dd($this->req); try { \DB::begintransaction(); $parent_id = empty($this->req['parent_id']) ? 0 : $this->req['parent_id']; $file = ''; if (!empty($_FILES['feed_file']['tmp_name'])) { $base_name = date('d_m_Y_') . md5($_FILES['feed_file']['name']) . rand(11111, 99999) . time(); $fl_name = $base_name . '.png'; $fl = file_get_contents($_FILES['feed_file']['tmp_name']); \Image::make($fl)->save($this->path . $fl_name); $file = $fl_name; } $feed = data_feedback::create(['title' => $this->req['feed_title'], 'ask' => $this->req['feed_ask'], 'link' => $this->req['feed_link'], 'parent_id' => $parent_id, 'file' => $file, 'id_karyawan' => \Me::data()->id_karyawan]); $kode = \Format::code($feed->id_feedback); $feed->kode = $kode; $feed->save(); if ($parent_id > 0) { $up = data_feedback::find($parent_id); $up->notif = $up->notif + 1; $up->save(); } \Loguser::create('Megisi form feedback Kode. #' . $kode); \DB::commit(); return ['label' => 'success', 'err' => 'Feedback berhasil terkirim dengan Kode. ' . $feed->kode]; } catch (\Exception $e) { \DB::rollback(); if (file_exists($this->path . $file)) { @unlink($this->path . $file); } return ['label' => 'danger', 'err' => $e->getMessage()]; } }
/** * Execute the job. * * @return void */ public function handle() { //dd($this->req); try { \DB::begintransaction(); $parent_id = empty($this->req['parent_id']) ? 0 : $this->req['parent_id']; $file = $this->req['file']; if (!empty($_FILES['feed_file']['tmp_name'])) { $base_name = date('d_m_Y_') . md5($_FILES['feed_file']['name']) . rand(11111, 99999) . time(); $fl_name = $base_name . '.png'; $fl = file_get_contents($_FILES['feed_file']['tmp_name']); \Image::make($fl)->save($this->path . $fl_name); $file = $fl_name; if (file_exists($this->path . $this->req['file'])) { @unlink($this->path . $this->req['file']); } } $title = empty($this->req['feed_title']) ? '' : $this->req['feed_title']; $link = empty($this->req['feed_link']) ? '' : $this->req['feed_link']; $feed = data_feedback::find($this->req['id']); $feed->update(['title' => $title, 'ask' => $this->req['feed_ask'], 'link' => $link, 'file' => $file]); \Loguser::create('Memperbaharui feedback Kode. ' . $feed->kode); \DB::commit(); return ['label' => 'success', 'err' => 'Feedback berhasil terkirim dengan Kode. ' . $feed->kode]; } catch (\Exception $e) { \DB::rollback(); if (file_exists($this->path . $file)) { @unlink($this->path . $file); } return ['label' => 'danger', 'err' => $e->getMessage()]; } }
public function getFeedback(Request $req) { if ($req->ajax()) { $total = data_feedback::notif()->first(); $res = $total->total > 9 ? '9+' : $total->total; return json_encode(['total' => $res]); } }
public function postDelcommen(Request $req) { if ($req->ajax()) { $item = data_feedback::find($req->id); if (!empty($item->file)) { $file = public_path() . '/img/feedback/' . $item->file; if (file_exists($file)) { @unlink($file); } } $item->delete(); return json_encode(['id' => $req->id]); } }