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