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