123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
-
- namespace App\Http\Controllers\Officer;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use Validator;
- use Hash;
-
- use App\SiteSetting;
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\Module\Department;
- use App\Model\Module\Roles;
-
- class ProfileController extends Controller
- {
- /**
- * Create a profile controller.
- *
- * @return value
- */
- public function staffProfile($_id){
- $id = Auth::guard('ofr')->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('officer.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', '<strong>Berjaya!</strong> kemaskini maklumat asas anda');
- }else {
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> 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->save();
-
- $staff->no_badan = $request->get('no_badan');
- $staff->save();
-
- return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> kemaskini kerjaya anda');
- }else {
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> 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', '<strong>Berjaya!</strong> kemaskini kata laluan anda');
- }else {
- return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> kemaskini kata laluan anda');
- }
- }
- }
|