Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1.  
  2. $validator = Validator::make($this->request->all(), [
  3. 'role' => array('required', 'in:'.implode(',' , array_keys($this->roles))),
  4. 'username' => array('required', 'unique:admins,username', 'min:3'),
  5. 'password' => array('required', 'min:6'),
  6. 'email' => array('required', 'email', 'unique:admins,email'),
  7. ]);
  8.  
  9. if ($validator->fails()) {
  10. return redirect('admins/add/'.$role)
  11. ->withInput()
  12. ->withErrors($validator);
  13. } else {
  14.  
  15. if(in_array($this->request->input('role'), $this->allowed_roles[Auth::guard('admin')->user()->role])) {
  16. $item = new Admin;
  17. $item->role = $this->request->input('role');
  18. $item->username = $this->request->input('username');
  19. $item->password = bcrypt($this->request->input('password'));
  20. $item->email = $this->request->input('email');
  21. $item->comments = $this->request->input('comments');
  22. $item->phone = $this->request->input('phone');
  23. $item->company_name = $this->request->input('company_name');
  24. $item->vat = $this->request->input('vat');
  25. $item->discount = $this->request->input('discount');
  26.  
  27. if( $this->request->input('role')=='employee' || $this->request->input('role')=='affiliate' ) {
  28. $item->manager_id = Auth::guard('admin')->user()->id;
  29. }
  30. if( $this->request->input('role')=='employee' ) {
  31. $item->hotel_id = Auth::guard('admin')->user()->hotel_id;
  32. }
  33. if( $this->request->input('role')=='manager' ) {
  34. $item->hotel_id = $this->request->input('hotel_id');
  35. }
  36.  
  37. $item->save();
  38.  
  39. if( Request::file('image') && Request::file('image')->isValid() ) {
  40. $img = Image::make( Input::file('image') )->orientate();
  41. $item->addImage($img);
  42. }
  43. }
  44.  
  45. $this->request->session()->flash('success-message', 'Account created');
  46. return redirect('admins');
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement