diff --git a/app/Http/Controllers/.fuse_hidden00000e0d00000001 b/app/Http/Controllers/.fuse_hidden00000e0d00000001 new file mode 100644 index 0000000000000000000000000000000000000000..a0704adba6c33592464777a96f1f259e4f2bc3b7 --- /dev/null +++ b/app/Http/Controllers/.fuse_hidden00000e0d00000001 @@ -0,0 +1,74 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use App\Http\Controllers\APIBaseController as APIBaseController; +use App\Sertifikat; +use App\Pegawai; +use Carbon\Carbon; +use Intervention\Image\ImageManagerStatic as Image; + +class SertifikatController extends APIBaseController +{ + + public function index(){ + $sertifikat = Sertifikat::all(); + return $this->sendResponse($sertifikat, 'Sertifikat created successfully.'); + } + + public function update(Request $request, $id){ + // if (!$this->authenticate(4)) {return $this->sendError('You are not authenticated.');} + + $input = $request->all(); + + $pegawai = Pegawai::find($id); + $list = array(); + + for ($i = 0; $i < count($input['sertifikat']); $i++) { + + $imageData = $input['sertifikat'][$i]['nama_file']; + + if(explode("/", $imageData)[0] === "data:image"){ + $fileName = $pegawai->nip . '_' . $i . '.' . explode('/', explode(':', substr($imageData, 0, strpos($imageData, ';')))[1])[1]; + $image = Image::make($imageData); + $image->save(public_path('sertifikat/').$fileName); + }else{ + $string = explode("/", $imageData); + $fileName = $string[count($string)-1]; + } + + $sertifikat = null; + if(!is_null($input['sertifikat'][$i]['id_sertifikat'])){ + $sertifikat = Sertifikat::find($input['sertifikat'][$i]['id_sertifikat']); + } + + if(is_null($sertifikat)){ + $postSertifikat = Sertifikat::create([ + 'id_pegawai' => $id, + 'nama_file' => $fileName, + 'judul' => $input['sertifikat'][$i]['judul'], + 'lembaga' => $input['sertifikat'][$i]['lembaga'], + 'tahun_diterbitkan' => $input['sertifikat'][$i]['tahun_diterbitkan'], + 'catatan' => $input['sertifikat'][$i]['catatan'], + ]); + array_push($list, $postSertifikat->id_sertifikat); + }else{ + $sertifikat->id_pegawai = $id; + $sertifikat->nama_file = $fileName; + $sertifikat->judul = $input['sertifikat'][$i]['judul']; + $sertifikat->lembaga = $input['sertifikat'][$i]['lembaga']; + $sertifikat->tahun_diterbitkan = $input['sertifikat'][$i]['tahun_diterbitkan']; + $sertifikat->catatan = $input['sertifikat'][$i]['catatan']; + + $sertifikat->save(); + array_push($list, $sertifikat->id_sertifikat); + } + } + + $data = Sertifikat::where('id_pegawai',$id)->whereNotIn('id_sertifikat', $list); + $data->delete(); + + return $this->sendResponse($input, 'Sertifikat updated successfully.'); + } +} diff --git a/app/Http/Controllers/SertifikatController.php b/app/Http/Controllers/SertifikatController.php index cc27cf820a3a2778e12f0eb5b1be02468c0d316a..a0704adba6c33592464777a96f1f259e4f2bc3b7 100644 --- a/app/Http/Controllers/SertifikatController.php +++ b/app/Http/Controllers/SertifikatController.php @@ -35,7 +35,7 @@ class SertifikatController extends APIBaseController $image->save(public_path('sertifikat/').$fileName); }else{ $string = explode("/", $imageData); - $fileName = $string[count($string-1)]; + $fileName = $string[count($string)-1]; } $sertifikat = null; diff --git a/public/sertifikat/256636605084866041_2.jpeg b/public/sertifikat/256636605084866041_2.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..4823a08a45852a48051ae81ca8fdedc8d0f7d89b Binary files /dev/null and b/public/sertifikat/256636605084866041_2.jpeg differ diff --git a/public/sertifikat/256636605084866041_3.jpeg b/public/sertifikat/256636605084866041_3.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..4823a08a45852a48051ae81ca8fdedc8d0f7d89b Binary files /dev/null and b/public/sertifikat/256636605084866041_3.jpeg differ