1 | <?php |
||
2 | |||
3 | namespace Devpri\Tinre\Http\Controllers\Auth; |
||
4 | |||
5 | use Devpri\Tinre\Events\UserRegistered; |
||
6 | use Devpri\Tinre\Http\Controllers\Controller; |
||
7 | use Devpri\Tinre\Models\User; |
||
8 | use Illuminate\Http\Request; |
||
9 | use Illuminate\Http\Response; |
||
10 | use Illuminate\Support\Facades\Auth; |
||
11 | use Illuminate\Support\Facades\Hash; |
||
12 | use Illuminate\Support\Facades\Validator; |
||
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. |
||
23 | | |
||
24 | */ |
||
25 | |||
26 | /** |
||
27 | * Where to redirect users after registration. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | 1 | public function redirectTo() |
|
32 | { |
||
33 | 1 | return route('dashboard'); |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Create a new controller instance. |
||
38 | * |
||
39 | * @return void |
||
40 | */ |
||
41 | 2 | public function __construct() |
|
42 | { |
||
43 | 2 | $this->middleware('guest'); |
|
44 | 2 | } |
|
45 | |||
46 | /** |
||
47 | * Show the application registration form. |
||
48 | * |
||
49 | * @return \Illuminate\Http\Response |
||
50 | */ |
||
51 | 1 | public function showRegistrationForm() |
|
52 | { |
||
53 | 1 | return view('tinre::auth.register'); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
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 | 1 | protected function validator(array $data) |
|
63 | { |
||
64 | 1 | return Validator::make($data, [ |
|
65 | 1 | 'name' => ['required', 'string', 'max:255'], |
|
66 | 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], |
||
67 | 'password' => ['required', 'string', 'min:8'], |
||
68 | ]); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Create a new user instance after a valid registration. |
||
73 | * |
||
74 | * @param array $data |
||
75 | * @return \App\User |
||
0 ignored issues
–
show
The type
App\User was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
76 | */ |
||
77 | 1 | protected function create(array $data) |
|
78 | { |
||
79 | 1 | return User::create([ |
|
0 ignored issues
–
show
|
|||
80 | 1 | 'name' => $data['name'], |
|
81 | 1 | 'email' => $data['email'], |
|
82 | 1 | 'role' => config('tinre.default_role'), |
|
83 | 1 | 'password' => Hash::make($data['password']), |
|
84 | ]); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Handle a registration request for the application. |
||
89 | * |
||
90 | * @param \Illuminate\Http\Request $request |
||
91 | * @return \Illuminate\Http\Response |
||
92 | */ |
||
93 | 1 | public function register(Request $request) |
|
94 | { |
||
95 | 1 | $this->validator($request->all())->validate(); |
|
96 | |||
97 | 1 | $user = $this->create($request->all()); |
|
98 | |||
99 | 1 | event(new UserRegistered($user)); |
|
100 | |||
101 | 1 | $this->guard()->login($user); |
|
102 | |||
103 | 1 | return $request->wantsJson() |
|
0 ignored issues
–
show
|
|||
104 | ? new Response('', 201) |
||
105 | 1 | : redirect($this->redirectTo()); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Get the guard to be used during registration. |
||
110 | * |
||
111 | * @return \Illuminate\Contracts\Auth\StatefulGuard |
||
112 | */ |
||
113 | 1 | protected function guard() |
|
114 | { |
||
115 | 1 | return Auth::guard(); |
|
116 | } |
||
117 | } |
||
118 |