RegisterController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Providers\RouteServiceProvider;
  5. use App\User;
  6. use Illuminate\Foundation\Auth\RegistersUsers;
  7. use Illuminate\Support\Facades\Hash;
  8. use Illuminate\Support\Facades\Validator;
  9. class RegisterController extends Controller
  10. {
  11. /*
  12. |--------------------------------------------------------------------------
  13. | Register Controller
  14. |--------------------------------------------------------------------------
  15. |
  16. | This controller handles the registration of new users as well as their
  17. | validation and creation. By default this controller uses a trait to
  18. | provide this functionality without requiring any additional code.
  19. |
  20. */
  21. use RegistersUsers;
  22. /**
  23. * Where to redirect users after registration.
  24. *
  25. * @var string
  26. */
  27. protected $redirectTo = RouteServiceProvider::HOME;
  28. /**
  29. * Create a new controller instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. $this->middleware('guest');
  36. }
  37. /**
  38. * Get a validator for an incoming registration request.
  39. *
  40. * @param array $data
  41. * @return \Illuminate\Contracts\Validation\Validator
  42. */
  43. protected function validator(array $data)
  44. {
  45. return Validator::make($data, [
  46. 'name' => ['required', 'string', 'max:255'],
  47. 'username' => ['required', 'string', 'max:255', 'unique:users'],
  48. 'mobile' => ['required', 'regex:/^09\d{9}$/', 'digits:11', 'numeric'],
  49. 'email' => ['required', 'string', 'email', 'max:255'],
  50. 'password' => ['required', 'string', 'min:8', 'confirmed'],
  51. 'g-recaptcha-response' => ['required', 'cutlet_recaptcha']
  52. ]);
  53. }
  54. /**
  55. * Create a new user instance after a valid registration.
  56. *
  57. * @param array $data
  58. * @return \App\User
  59. */
  60. protected function create(array $data)
  61. {
  62. return User::create([
  63. 'name' => $data['name'],
  64. 'username' => $data['username'],
  65. 'mobile' => $data['mobile'],
  66. 'email' => $data['email'],
  67. 'password' => Hash::make($data['password']),
  68. ]);
  69. }
  70. }