id(); $user = Staff::with('StaffDetail')->find($id); $staff = StaffDetail::where('_id',$_id)->first(); $site = SiteSetting::first(); $department = Department::all(); $roles = Roles::all(); $access = array(); if($staff->roles_access == "Pegawai"){ foreach($staff->roles_ids as $r){ $role = Roles::where('_id',$r)->first(); array_push($access, array( 'kod' => $role->kod )); } // $access = json_encode($access); } if(empty($access)){ $access = 'null'; } $myDepartment = Department::whereHas('StaffDetail', function($q) use ($_id) { $q->where('_id', $_id); })->select('jbkod', 'jnama')->get(); return view('main-dashboard.profile', compact('user','_id','department','staff','access','roles','myDepartment','site')); } public function updateBasic(Request $request){ $validator = Validator::make($request->all(), [ 'profil' => 'mimes:jpeg,jpg|max:2048', ]); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } $staff = Staff::with('StaffDetail')->where('_id', $request->_id)->first(); if(!empty($staff)) { if($request->hasFile('profil')){ $destinationPath = 'uploads/profile'; $uploaded = public_path().'/'.$destinationPath; $allowedfileExtension = ['jpeg','jpg']; $a = $request->file('profil'); $extension = $a->getClientOriginalExtension(); $filename = $staff->StaffDetail->no_badan; $a->move($destinationPath,$filename.'.'.$extension); $profile_img = '/'.$destinationPath.'/'.$filename.'.'.$extension; $staff->StaffDetail->profile_img = $profile_img; $staff->StaffDetail->save(); } $staff->StaffDetail->full_name = $request->get('full_name'); $staff->StaffDetail->identity = $request->get('identity'); $staff->StaffDetail->mobile = $request->get('mobile'); $staff->StaffDetail->save(); return redirect()->back()->with('success_msg', 'Berjaya! kemaskini maklumat asas anda'); }else { return redirect()->back()->withInput()->with('error_msg','Tidak Berjaya! kemaskini maklumat asas anda'); } } public function updateWork(Request $request){ $staff = Staff::with('StaffDetail')->where('_id', $request->_id)->first(); if(!empty($staff)) { $staff->StaffDetail->gred = $request->get('gred'); $staff->StaffDetail->no_badan = $request->get('no_badan'); // $staff->StaffDetail->jbkod = $request->get('jbkod'); $staff->StaffDetail->save(); $staff->no_badan = $request->get('no_badan'); $staff->save(); return redirect()->back()->with('success_msg', 'Berjaya! kemaskini kerjaya anda'); }else { return redirect()->back()->withInput()->with('error_msg','Tidak Berjaya! kemaskini kerjaya anda'); } } public function updatePassword(Request $request){ $validator = Validator::make($request->all(), [ 'password' => 'min:8|confirmed', ]); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } $staff = Staff::with('StaffDetail')->where('_id', $request->_id)->first(); if(!empty($staff)) { $encryptP = Hash::make($request->get('password')); $staff->password = $encryptP; $staff->save(); $staff->StaffDetail->password = $encryptP; $staff->StaffDetail->save(); return redirect()->back()->with('success_msg', 'Berjaya! kemaskini kata laluan anda'); }else { return redirect()->back()->withInput()->with('error_msg','Tidak Berjaya! kemaskini kata laluan anda'); } } }