Passed
Push — master ( 5aafeb...af0530 )
by Karel
12:33 queued 05:20
created

src/Controllers/Auth/RegisterController.php (1 issue)

1
<?php
2
3
namespace Chuckbe\Chuckcms\Controllers\Auth;
4
5
use Chuckbe\Chuckcms\Models\User;
6
use Chuckbe\Chuckcms\Chuck\UserRepository;
7
use Illuminate\Support\Facades\Validator;
8
use Illuminate\Foundation\Auth\RegistersUsers;
9
10
use Illuminate\Foundation\Bus\DispatchesJobs;
11
use Illuminate\Routing\Controller as BaseController;
12
use Illuminate\Foundation\Validation\ValidatesRequests;
13
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
14
15
class RegisterController extends BaseController
16
{
17
    /*
18
    |--------------------------------------------------------------------------
19
    | Register Controller
20
    |--------------------------------------------------------------------------
21
    |
22
    | This controller handles the registration of new users as well as their
23
    | validation and creation. By default this controller uses a trait to
24
    | provide this functionality without requiring any additional code.
25
    |
26
    */
27
28
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, RegistersUsers;
29
30
    /**
31
     * Where to redirect users after registration.
32
     *
33
     * @var string
34
     */
35
    protected $redirectTo = '/dashboard';
36
37
    /**
38
     * User Repository.
39
     *
40
     * @var string
41
     */
42
    private $userRepository;
43
44
    /**
45
     * Create a new controller instance.
46
     *
47
     * @return void
48
     */
49
    public function __construct(UserRepository $userRepository)
50
    {
51
        $this->userRepository = $userRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $userRepository of type Chuckbe\Chuckcms\Chuck\UserRepository is incompatible with the declared type string of property $userRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

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