Completed
Push — master ( 7ec104...6d5219 )
by Sergi Tur
98:33 queued 68:39
created

src/stubs/RegisterController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\User;
6
use Validator;
7
use App\Http\Controllers\Controller;
8
use Illuminate\Foundation\Auth\RegistersUsers;
9
10
/**
11
 * Class RegisterController
12
 * @package %%NAMESPACE%%\Http\Controllers\Auth
13
 */
14
class RegisterController extends Controller
15
{
16
    /*
17
    |--------------------------------------------------------------------------
18
    | Register Controller
19
    |--------------------------------------------------------------------------
20
    |
21
    | This controller handles the registration of new users as well as their
22
    | validation and creation. By default this controller uses a trait to
23
    | provide this functionality without requiring any additional code.
24
    |
25
    */
26
27
    use RegistersUsers;
28
29
    /**
30
     * Show the application registration form.
31
     *
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function showRegistrationForm()
35
    {
36
        return view('adminlte::auth.register');
37
    }
38
39
    /**
40
     * Where to redirect users after login / registration.
41
     *
42
     * @var string
43
     */
44
    protected $redirectTo = '/home';
45
46
    /**
47
     * Create a new controller instance.
48
     *
49
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
50
     */
51
    public function __construct()
52
    {
53
        $this->middleware('guest');
54
    }
55
56
    /**
57
     * Get a validator for an incoming registration request.
58
     *
59
     * @param  array  $data
60
     * @return \Illuminate\Contracts\Validation\Validator
61
     */
62
    protected function validator(array $data)
63
    {
64
        return Validator::make($data, [
65
            'name'     => 'required|max:255',
66
            'username' => 'sometimes|required|max:255|unique:users',
67
            'email'    => 'required|email|max:255|unique:users',
68
            'password' => 'required|min:6|confirmed',
69
            'terms'    => 'required',
70
        ]);
71
    }
72
73
    /**
74
     * Create a new user instance after a valid registration.
75
     *
76
     * @param  array  $data
77
     * @return User
78
     */
79
    protected function create(array $data)
80
    {
81
        $fields = [
82
            'name'     => $data['name'],
83
            'email'    => $data['email'],
84
            'password' => bcrypt($data['password']),
85
        ];
86
        if (config('auth.providers.users.field','email') === 'username' && isset($data['username'])) {
87
            $fields['username'] = $data['username'];
88
        }
89
        return User::create($fields);
90
    }
91
}
92