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