Dashboard sipadu mbip
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ProfileController.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace App\Http\Controllers\Main;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Validator;
  7. use Hash;
  8. use App\SiteSetting;
  9. use App\Model\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\Module\Department;
  12. use App\Model\Module\Roles;
  13. class ProfileController extends Controller
  14. {
  15. /**
  16. * Create a profile controller.
  17. *
  18. * @return value
  19. */
  20. public function staffProfile($_id){
  21. $id = Auth::guard('sadmin')->id();
  22. $user = Staff::with('StaffDetail')->find($id);
  23. $staff = StaffDetail::where('_id',$_id)->first();
  24. $site = SiteSetting::first();
  25. $department = Department::all();
  26. $roles = Roles::all();
  27. $access = array();
  28. if($staff->roles_access == "Pegawai"){
  29. foreach($staff->roles_ids as $r){
  30. $role = Roles::where('_id',$r)->first();
  31. array_push($access, array(
  32. 'kod' => $role->kod
  33. ));
  34. }
  35. // $access = json_encode($access);
  36. }
  37. if(empty($access)){
  38. $access = 'null';
  39. }
  40. $myDepartment = Department::whereHas('StaffDetail', function($q) use ($_id) {
  41. $q->where('_id', $_id);
  42. })->select('jbkod', 'jnama')->get();
  43. return view('main-dashboard.profile', compact('user','_id','department','staff','access','roles','myDepartment','site'));
  44. }
  45. public function updateBasic(Request $request){
  46. $validator = Validator::make($request->all(), [
  47. 'profil' => 'mimes:jpeg,jpg|max:2048',
  48. ]);
  49. if ($validator->fails()) {
  50. return redirect()->back()->withInput()->withErrors($validator);
  51. }
  52. $staff = Staff::with('StaffDetail')->where('_id', $request->_id)->first();
  53. if(!empty($staff)) {
  54. if($request->hasFile('profil')){
  55. $destinationPath = 'uploads/profile';
  56. $uploaded = public_path().'/'.$destinationPath;
  57. $allowedfileExtension = ['jpeg','jpg'];
  58. $a = $request->file('profil');
  59. $extension = $a->getClientOriginalExtension();
  60. $filename = $staff->StaffDetail->no_badan;
  61. $a->move($destinationPath,$filename.'.'.$extension);
  62. $profile_img = '/'.$destinationPath.'/'.$filename.'.'.$extension;
  63. $staff->StaffDetail->profile_img = $profile_img;
  64. $staff->StaffDetail->save();
  65. }
  66. $staff->StaffDetail->full_name = $request->get('full_name');
  67. $staff->StaffDetail->identity = $request->get('identity');
  68. $staff->StaffDetail->mobile = $request->get('mobile');
  69. $staff->StaffDetail->save();
  70. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> kemaskini maklumat asas anda');
  71. }else {
  72. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> kemaskini maklumat asas anda');
  73. }
  74. }
  75. public function updateWork(Request $request){
  76. $staff = Staff::with('StaffDetail')->where('_id', $request->_id)->first();
  77. if(!empty($staff)) {
  78. $staff->StaffDetail->gred = $request->get('gred');
  79. $staff->StaffDetail->no_badan = $request->get('no_badan');
  80. // $staff->StaffDetail->jbkod = $request->get('jbkod');
  81. $staff->StaffDetail->save();
  82. $staff->no_badan = $request->get('no_badan');
  83. $staff->save();
  84. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> kemaskini kerjaya anda');
  85. }else {
  86. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> kemaskini kerjaya anda');
  87. }
  88. }
  89. public function updatePassword(Request $request){
  90. $validator = Validator::make($request->all(), [
  91. 'password' => 'min:8|confirmed',
  92. ]);
  93. if ($validator->fails()) {
  94. return redirect()->back()->withInput()->withErrors($validator);
  95. }
  96. $staff = Staff::with('StaffDetail')->where('_id', $request->_id)->first();
  97. if(!empty($staff)) {
  98. $encryptP = Hash::make($request->get('password'));
  99. $staff->password = $encryptP;
  100. $staff->save();
  101. $staff->StaffDetail->password = $encryptP;
  102. $staff->StaffDetail->save();
  103. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> kemaskini kata laluan anda');
  104. }else {
  105. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> kemaskini kata laluan anda');
  106. }
  107. }
  108. }