質問編集履歴
3
[RegistersUsers.php]コードを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,8 +38,146 @@
|
|
38
38
|
|
39
39
|
#コード画面
|
40
40
|
|
41
|
+
|
42
|
+
|
41
43
|
```ここに言語を入力
|
42
44
|
|
45
|
+
#C:\Users\H Yokota\code\sampleapp\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<?php
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
namespace Illuminate\Foundation\Auth;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
use Illuminate\Http\Request;
|
58
|
+
|
59
|
+
use Illuminate\Support\Facades\Auth;
|
60
|
+
|
61
|
+
use Illuminate\Auth\Events\Registered;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
trait RegistersUsers
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
use RedirectsUsers;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
/**
|
74
|
+
|
75
|
+
* Show the application registration form.
|
76
|
+
|
77
|
+
*
|
78
|
+
|
79
|
+
* @return \Illuminate\Http\Response
|
80
|
+
|
81
|
+
*/
|
82
|
+
|
83
|
+
public function showRegistrationForm()
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
return view('auth.register');
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
|
95
|
+
* Handle a registration request for the application.
|
96
|
+
|
97
|
+
*
|
98
|
+
|
99
|
+
* @param \Illuminate\Http\Request $request
|
100
|
+
|
101
|
+
* @return \Illuminate\Http\Response
|
102
|
+
|
103
|
+
*/
|
104
|
+
|
105
|
+
public function register(Request $request)
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
$this->validator($request->all())->validate();
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
event(new Registered($user = $this->create($request->all())));
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
$this->guard()->login($user);
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
return $this->registered($request, $user)
|
122
|
+
|
123
|
+
?: redirect($this->redirectPath());
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
/**
|
130
|
+
|
131
|
+
* Get the guard to be used during registration.
|
132
|
+
|
133
|
+
*
|
134
|
+
|
135
|
+
* @return \Illuminate\Contracts\Auth\StatefulGuard
|
136
|
+
|
137
|
+
*/
|
138
|
+
|
139
|
+
protected function guard()
|
140
|
+
|
141
|
+
{
|
142
|
+
|
143
|
+
return Auth::guard();
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
/**
|
150
|
+
|
151
|
+
* The user has been registered.
|
152
|
+
|
153
|
+
*
|
154
|
+
|
155
|
+
* @param \Illuminate\Http\Request $request
|
156
|
+
|
157
|
+
* @param mixed $user
|
158
|
+
|
159
|
+
* @return mixed
|
160
|
+
|
161
|
+
*/
|
162
|
+
|
163
|
+
protected function registered(Request $request, $user)
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
//
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```ここに言語を入力
|
180
|
+
|
43
181
|
#C:\Users\%USERPROFILE%\code\sampleapp\app\Http\Controllers\Auth\RegisterController.php
|
44
182
|
|
45
183
|
<?php
|
2
RegisterControllerクラスを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,6 +40,158 @@
|
|
40
40
|
|
41
41
|
```ここに言語を入力
|
42
42
|
|
43
|
+
#C:\Users\%USERPROFILE%\code\sampleapp\app\Http\Controllers\Auth\RegisterController.php
|
44
|
+
|
45
|
+
<?php
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
namespace App\Http\Controllers\Auth;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
use App\User;
|
54
|
+
|
55
|
+
use App\Http\Controllers\Controller;
|
56
|
+
|
57
|
+
use Illuminate\Support\Facades\Validator;
|
58
|
+
|
59
|
+
use Illuminate\Foundation\Auth\RegistersUsers;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
class RegisterController extends Controller
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
/*
|
68
|
+
|
69
|
+
|--------------------------------------------------------------------------
|
70
|
+
|
71
|
+
| Register Controller
|
72
|
+
|
73
|
+
|--------------------------------------------------------------------------
|
74
|
+
|
75
|
+
|
|
76
|
+
|
77
|
+
| This controller handles the registration of new users as well as their
|
78
|
+
|
79
|
+
| validation and creation. By default this controller uses a trait to
|
80
|
+
|
81
|
+
| provide this functionality without requiring any additional code.
|
82
|
+
|
83
|
+
|
|
84
|
+
|
85
|
+
*/
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
use RegistersUsers;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
|
95
|
+
* Where to redirect users after registration.
|
96
|
+
|
97
|
+
*
|
98
|
+
|
99
|
+
* @var string
|
100
|
+
|
101
|
+
*/
|
102
|
+
|
103
|
+
protected $redirectTo = '/home';
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
/**
|
108
|
+
|
109
|
+
* Create a new controller instance.
|
110
|
+
|
111
|
+
*
|
112
|
+
|
113
|
+
* @return void
|
114
|
+
|
115
|
+
*/
|
116
|
+
|
117
|
+
public function __construct()
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
$this->middleware('guest');
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
/**
|
128
|
+
|
129
|
+
* Get a validator for an incoming registration request.
|
130
|
+
|
131
|
+
*
|
132
|
+
|
133
|
+
* @param array $data
|
134
|
+
|
135
|
+
* @return \Illuminate\Contracts\Validation\Validator
|
136
|
+
|
137
|
+
*/
|
138
|
+
|
139
|
+
protected function validator(array $data)
|
140
|
+
|
141
|
+
{
|
142
|
+
|
143
|
+
return Validator::make($data, [
|
144
|
+
|
145
|
+
'name' => 'required|string|max:255',
|
146
|
+
|
147
|
+
'email' => 'required|string|email|max:255|unique:users',
|
148
|
+
|
149
|
+
'password' => 'required|string|min:6|confirmed',
|
150
|
+
|
151
|
+
]);
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
/**
|
158
|
+
|
159
|
+
* Create a new user instance after a valid registration.
|
160
|
+
|
161
|
+
*
|
162
|
+
|
163
|
+
* @param array $data
|
164
|
+
|
165
|
+
* @return \App\User
|
166
|
+
|
167
|
+
*/
|
168
|
+
|
169
|
+
protected function create(array $data)
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
return User::create([
|
174
|
+
|
175
|
+
'name' => $data['name'],
|
176
|
+
|
177
|
+
'email' => $data['email'],
|
178
|
+
|
179
|
+
'password' => bcrypt($data['password']),
|
180
|
+
|
181
|
+
]);
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
```ここに言語を入力
|
194
|
+
|
43
195
|
#home.blade.php
|
44
196
|
|
45
197
|
<html>
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
#やったこと
|
12
12
|
|
13
|
-
1.
|
13
|
+
1.データベースの準備(マイグレーションの実行)
|
14
14
|
|
15
15
|
→マイグレーションの実行([php artisan migrate])
|
16
16
|
|