UsersController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\User;
  7. use Validator;
  8. use App\Models\CompanyModel;
  9. use App\Models\Role;
  10. class UsersController extends Controller
  11. {
  12. public function index(){
  13. $data['title'] = "User management";
  14. $data['all'] = User::orderBy('utype')->get();
  15. $data['client_list']=CompanyModel::where('status',2)->get();
  16. $data['roles']=Role::orderBy('name','ASC')->get();
  17. return view('admin.users',$data);
  18. /*
  19. 1=Created;
  20. 2=in process;
  21. 3=Completed;
  22. 4=checking;
  23. 5=bugfixing;
  24. 5=done;
  25. */
  26. }
  27. public function add_user(Request $req){
  28. $name = $req->name;
  29. $email = $req->email;
  30. $mob = $req->mob;
  31. $address = $req->address;
  32. $company = $req->company;
  33. $website = $req->website;
  34. $user_type = $req->user_type;
  35. $password = bcrypt($req->password);
  36. $sav = new User;
  37. $sav->employee_id= $req->e_id;
  38. $sav->designation= $req->designation;
  39. $sav->name = $name;
  40. $sav->email = $email;
  41. $sav->mob = $mob;
  42. $sav->address = $address;
  43. $sav->company = $company;
  44. $sav->website = $website;
  45. $sav->utype = $user_type;
  46. $sav->password = $password;
  47. $sav->active = 1;
  48. $sav->save();
  49. if (!empty($req->input('role'))) {
  50. $sav->attachRole($req->role);
  51. }
  52. return redirect()->back()->with('msg','Data saved !!');
  53. }
  54. public function user_active($id)
  55. {
  56. $user = User::find($id);
  57. if($user->active == 0){
  58. $user->active = 1;
  59. $status = 'published';
  60. }else{
  61. $user->active = 0;
  62. $status = 'unpublished';
  63. }
  64. $user->update();
  65. return back();
  66. }
  67. public function change_user_pass(Request $req){
  68. $id = $req->user_id;
  69. $password = $req->password;
  70. $data = [
  71. 'password' => $req->password,
  72. 'password_confirmation' => $req->password_confirmation,
  73. ];
  74. $validator = Validator::make($data, [
  75. 'password' => 'required|min:6|confirmed',
  76. ]);
  77. if($validator->fails()){
  78. return redirect()->back()->with('msg','Operation failed');
  79. }
  80. else{
  81. $sav = User::find($id);
  82. $sav->password = bcrypt($password);
  83. $sav->save();
  84. return redirect()->back()->with('msg','Password changed successfully !');
  85. }
  86. }
  87. }