質問編集履歴
3
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,24 +1,118 @@
|
|
1
1
|
laravelでアプリをつくり、heorkuにデプロイしました。
|
2
2
|
|
3
|
-
|
3
|
+
AuthenticatesUsersのlogout()をオーバーライドして、ログイン時みたいにメッセージを出したいです。
|
4
4
|
|
5
5
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
LoginController.php
|
20
|
+
|
21
|
+
|
22
|
+
|
9
23
|
```ここに言語を入力
|
10
24
|
|
11
|
-
|
25
|
+
<?php
|
12
26
|
|
13
|
-
|
27
|
+
namespace App\Http\Controllers\Auth;
|
14
28
|
|
15
|
-
<p class="flash_meg--txt"> {{ session('flash_message') }}
|
16
29
|
|
17
|
-
<i class="far fa-thumbs-up"></i>
|
18
30
|
|
19
|
-
|
31
|
+
use App\Http\Controllers\Controller;
|
20
32
|
|
33
|
+
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
class LoginController extends Controller
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
/*
|
42
|
+
|
43
|
+
|--------------------------------------------------------------------------
|
44
|
+
|
45
|
+
| Login Controller
|
46
|
+
|
47
|
+
|--------------------------------------------------------------------------
|
48
|
+
|
49
|
+
|
|
50
|
+
|
51
|
+
| This controller handles authenticating users for the application and
|
52
|
+
|
53
|
+
| redirecting them to your home screen. The controller uses a trait
|
54
|
+
|
55
|
+
| to conveniently provide its functionality to your applications.
|
56
|
+
|
57
|
+
|
|
58
|
+
|
59
|
+
*/
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
use AuthenticatesUsers;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
/**
|
68
|
+
|
69
|
+
* Where to redirect users after login.
|
70
|
+
|
71
|
+
*
|
72
|
+
|
73
|
+
* @var string
|
74
|
+
|
75
|
+
*/
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
protected function redirectTo() {
|
82
|
+
|
83
|
+
session()->flash('flash_message', 'ログインしました');
|
84
|
+
|
21
|
-
|
85
|
+
return '/';
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
/**
|
92
|
+
|
93
|
+
* Create a new controller instance.
|
94
|
+
|
95
|
+
*
|
96
|
+
|
97
|
+
* @return void
|
98
|
+
|
99
|
+
*/
|
100
|
+
|
101
|
+
public function __construct()
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
$this->middleware('guest')->except('logout');
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
}
|
22
116
|
|
23
117
|
|
24
118
|
|
@@ -40,9 +134,7 @@
|
|
40
134
|
|
41
135
|
|
42
136
|
|
43
|
-
|
44
|
-
|
45
|
-
###
|
137
|
+
###
|
46
138
|
|
47
139
|
|
48
140
|
|
@@ -54,174 +146,32 @@
|
|
54
146
|
|
55
147
|
|
56
148
|
|
149
|
+
public function logout(Request $request){
|
57
150
|
|
151
|
+
|
58
152
|
|
59
|
-
|
153
|
+
$this->guard()->logout();
|
60
154
|
|
61
155
|
|
62
156
|
|
63
|
-
|
157
|
+
$request->session()->invalidate();
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
return $this->loggedOut($request) ?: redirect('/');
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
```
|
64
170
|
|
65
171
|
|
66
172
|
|
67
173
|
|
68
174
|
|
69
|
-
use App\Http\Controllers\Controller;
|
70
|
-
|
71
|
-
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
72
|
-
|
73
|
-
use Illuminate\Http\Request;
|
74
|
-
|
75
|
-
use Illuminate\Support\Facades\Auth;
|
76
175
|
|
77
176
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
class LoginController extends Controller
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
/*
|
86
|
-
|
87
|
-
|--------------------------------------------------------------------------
|
88
|
-
|
89
|
-
| Login Controller
|
90
|
-
|
91
|
-
|--------------------------------------------------------------------------
|
92
|
-
|
93
|
-
|
|
94
|
-
|
95
|
-
| This controller handles authenticating users for the application and
|
96
|
-
|
97
|
-
| redirecting them to your home screen. The controller uses a trait
|
98
|
-
|
99
|
-
| to conveniently provide its functionality to your applications.
|
100
|
-
|
101
|
-
|
|
102
|
-
|
103
|
-
*/
|
104
|
-
|
105
|
-
use AuthenticatesUsers;
|
106
|
-
|
107
|
-
/**
|
108
|
-
|
109
|
-
* Where to redirect users after login.
|
110
|
-
|
111
|
-
*
|
112
|
-
|
113
|
-
* @var string
|
114
|
-
|
115
|
-
*/
|
116
|
-
|
117
|
-
protected $redirectTo = '/';
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
/**
|
122
|
-
|
123
|
-
* Create a new controller instance.
|
124
|
-
|
125
|
-
*
|
126
|
-
|
127
|
-
* @return void
|
128
|
-
|
129
|
-
*/
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
public function showLoginForm()
|
136
|
-
|
137
|
-
{
|
138
|
-
|
139
|
-
return view('authBuyer.login');
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
/**
|
148
|
-
|
149
|
-
*
|
150
|
-
|
151
|
-
* @param \Illuminate\Http\Request $request
|
152
|
-
|
153
|
-
*
|
154
|
-
|
155
|
-
* @return Response
|
156
|
-
|
157
|
-
*/
|
158
|
-
|
159
|
-
public function authenticate(Request $request){
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
$request->validate([
|
164
|
-
|
165
|
-
'email' => 'required|string|email|',
|
166
|
-
|
167
|
-
'password' =>'required|string|',
|
168
|
-
|
169
|
-
]);
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
if( Auth::guard('buyers')::attempt(['email'=>$request->input('email'),'password'=>$request->input('password')])){
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
return redirect()->route('products.index')->with('flash_message', 'ログインしました');
|
178
|
-
|
179
|
-
}else{
|
180
|
-
|
181
|
-
return redirect()->back()->with('flash_message', 'ログインに失敗しました');
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
protected function guard()
|
190
|
-
|
191
|
-
{
|
192
|
-
|
193
|
-
return Auth::guard('buyers');
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
public function logout(Request $request)
|
200
|
-
|
201
|
-
{
|
202
|
-
|
203
|
-
Auth::guard('buyers')->logout();
|
204
|
-
|
205
|
-
$request->session()->flush();
|
206
|
-
|
207
|
-
$request->session()->regenerate();
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
return redirect()->route('products.index')->with('flash_message', 'ログアウトしました');
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
```
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
こちらのコードでログアウトは動きました。
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
何か
|
177
|
+
何かいい方法はありますでしょうか
|
2
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,69 +46,181 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
AuthenticatesUsers
|
50
|
+
|
51
|
+
|
52
52
|
|
53
53
|
```ここに言語を入力
|
54
54
|
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
<?php
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
namespace App\Http\Controllers\AuthBuyer;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
use App\Http\Controllers\Controller;
|
70
|
+
|
71
|
+
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
72
|
+
|
73
|
+
use Illuminate\Http\Request;
|
74
|
+
|
75
|
+
use Illuminate\Support\Facades\Auth;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
class LoginController extends Controller
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
/*
|
86
|
+
|
87
|
+
|--------------------------------------------------------------------------
|
88
|
+
|
89
|
+
| Login Controller
|
90
|
+
|
91
|
+
|--------------------------------------------------------------------------
|
92
|
+
|
93
|
+
|
|
94
|
+
|
95
|
+
| This controller handles authenticating users for the application and
|
96
|
+
|
97
|
+
| redirecting them to your home screen. The controller uses a trait
|
98
|
+
|
99
|
+
| to conveniently provide its functionality to your applications.
|
100
|
+
|
101
|
+
|
|
102
|
+
|
103
|
+
*/
|
104
|
+
|
105
|
+
use AuthenticatesUsers;
|
106
|
+
|
107
|
+
/**
|
108
|
+
|
109
|
+
* Where to redirect users after login.
|
110
|
+
|
111
|
+
*
|
112
|
+
|
113
|
+
* @var string
|
114
|
+
|
115
|
+
*/
|
116
|
+
|
55
|
-
|
117
|
+
protected $redirectTo = '/';
|
118
|
+
|
119
|
+
|
120
|
+
|
56
|
-
|
121
|
+
/**
|
122
|
+
|
57
|
-
|
123
|
+
* Create a new controller instance.
|
124
|
+
|
58
|
-
|
125
|
+
*
|
126
|
+
|
127
|
+
* @return void
|
128
|
+
|
129
|
+
*/
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
59
|
-
|
135
|
+
public function showLoginForm()
|
60
|
-
|
136
|
+
|
61
|
-
|
137
|
+
{
|
62
|
-
|
138
|
+
|
63
|
-
|
139
|
+
return view('authBuyer.login');
|
64
|
-
|
65
|
-
|
140
|
+
|
66
|
-
|
67
|
-
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
68
|
-
|
147
|
+
/**
|
148
|
+
|
69
|
-
|
149
|
+
*
|
150
|
+
|
151
|
+
* @param \Illuminate\Http\Request $request
|
152
|
+
|
153
|
+
*
|
154
|
+
|
155
|
+
* @return Response
|
156
|
+
|
157
|
+
*/
|
158
|
+
|
159
|
+
public function authenticate(Request $request){
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
$request->validate([
|
164
|
+
|
165
|
+
'email' => 'required|string|email|',
|
166
|
+
|
167
|
+
'password' =>'required|string|',
|
168
|
+
|
169
|
+
]);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
if( Auth::guard('buyers')::attempt(['email'=>$request->input('email'),'password'=>$request->input('password')])){
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
return redirect()->route('products.index')->with('flash_message', 'ログインしました');
|
178
|
+
|
179
|
+
}else{
|
180
|
+
|
181
|
+
return redirect()->back()->with('flash_message', 'ログインに失敗しました');
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
protected function guard()
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
return Auth::guard('buyers');
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
public function logout(Request $request)
|
200
|
+
|
201
|
+
{
|
202
|
+
|
203
|
+
Auth::guard('buyers')->logout();
|
204
|
+
|
205
|
+
$request->session()->flush();
|
206
|
+
|
207
|
+
$request->session()->regenerate();
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
return redirect()->route('products.index')->with('flash_message', 'ログアウトしました');
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
}
|
70
218
|
|
71
219
|
```
|
72
220
|
|
73
221
|
|
74
222
|
|
75
|
-
AuthenticatesUsers
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
```ここに言語を入力
|
80
|
-
|
81
|
-
protected function sendLoginResponse(Request $request)
|
82
|
-
|
83
|
-
{
|
84
|
-
|
85
|
-
$request->session()->regenerate();
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
$this->clearLoginAttempts($request);
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
return $this->authenticated($request, $this->guard()->user())
|
94
|
-
|
95
|
-
?: redirect()->with('flash_message', 'ログインしました')->intended($this->redirectPath());
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
```
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
223
|
+
こちらのコードでログアウトは動きました。
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
224
|
|
113
225
|
|
114
226
|
|
1
コードの追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
laravelの
|
1
|
+
laravelのログイン時にフラッシュメッセージを出したい
|
test
CHANGED
@@ -1,86 +1,10 @@
|
|
1
1
|
laravelでアプリをつくり、heorkuにデプロイしました。
|
2
2
|
|
3
|
-
|
3
|
+
app.blade.phpの方でsettionは定義済みで、他の処理ではうまくsettionに入ります。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
以下は買う人のログインするための処理なのですが
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
フラッシュメッセージがうまく作動しません。他の場所では動くので、Controller側の処理が何かおかしいと思うのですが、どこか直すべきところはありますでしょうか。ログアウトは大丈夫です。
|
12
4
|
|
13
5
|
|
14
6
|
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
loginController.php
|
24
|
-
|
25
|
-
```ここに言語を入力
|
26
|
-
|
27
|
-
public function authenticate(Request $request)
|
28
|
-
|
29
|
-
{
|
30
|
-
|
31
|
-
$request->validate([
|
32
|
-
|
33
|
-
'email' => 'required|string|email|',
|
34
|
-
|
35
|
-
'password' => ['required','string'],
|
36
|
-
|
37
|
-
]);
|
38
|
-
|
39
|
-
if( Auth::guard('buyers')::attempt(['email'=>$request->input('email'),'password'=>$request->input('password')])){
|
40
|
-
|
41
|
-
$request->session()->flush();
|
42
|
-
|
43
|
-
$request->session()->regenerate();
|
44
|
-
|
45
|
-
//ログインのフラッシュメッセージは出ない!
|
46
|
-
|
47
|
-
return redirect()->route('products.index')->with('flash_message', 'ログインしました');
|
48
|
-
|
49
|
-
}else{
|
50
|
-
|
51
|
-
return redirect()->back()->with('flash_message', 'ログインに失敗しました');
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
//ログアウトのフラッシュメッセージは成功する!
|
60
|
-
|
61
|
-
public function logout(Request $request)
|
62
|
-
|
63
|
-
{
|
64
|
-
|
65
|
-
Auth::guard('buyers')->logout();
|
66
|
-
|
67
|
-
$request->session()->flush();
|
68
|
-
|
69
|
-
$request->session()->regenerate();
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
return redirect()->route('products.index')->with('flash_message', 'ログアウトしました');
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
```
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
app.blade.php
|
84
8
|
|
85
9
|
```ここに言語を入力
|
86
10
|
|
@@ -98,63 +22,79 @@
|
|
98
22
|
|
99
23
|
|
100
24
|
|
25
|
+
|
26
|
+
|
101
27
|
@endif
|
102
28
|
|
103
29
|
```
|
104
30
|
|
105
31
|
|
106
32
|
|
107
|
-
また、以下はローカル環境では、フラッシュメッセージが入るが、herokkuだと動かないです。。。
|
108
33
|
|
109
34
|
|
110
35
|
|
111
36
|
|
112
37
|
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
### 試したコード
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
113
|
-
|
51
|
+
loginController.php
|
114
52
|
|
115
53
|
```ここに言語を入力
|
116
54
|
|
55
|
+
protected $redirectTo = '/';
|
56
|
+
|
57
|
+
|
58
|
+
|
117
|
-
p
|
59
|
+
protected function redirectTo()
|
118
60
|
|
119
61
|
{
|
120
62
|
|
121
|
-
$this->
|
63
|
+
return redirect($this->redirectTo)
|
64
|
+
|
65
|
+
->with('flash_message', 'ログインしました');
|
66
|
+
|
67
|
+
}
|
122
68
|
|
123
69
|
|
124
70
|
|
125
|
-
|
71
|
+
```
|
126
72
|
|
127
73
|
|
128
74
|
|
129
|
-
|
75
|
+
AuthenticatesUsers
|
130
76
|
|
131
77
|
|
132
78
|
|
133
|
-
return $this->registered($request, $user)
|
134
|
-
|
135
|
-
?: redirect($this->redirectPath())->with('flash_message', 'アカウント登録が完了しました');
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
```
|
140
|
-
|
141
|
-
AuthenticatesUsers.php
|
142
|
-
|
143
79
|
```ここに言語を入力
|
144
80
|
|
145
|
-
p
|
81
|
+
protected function sendLoginResponse(Request $request)
|
146
82
|
|
147
83
|
{
|
148
84
|
|
149
|
-
$t
|
85
|
+
$request->session()->regenerate();
|
150
86
|
|
151
87
|
|
152
88
|
|
153
|
-
$
|
89
|
+
$this->clearLoginAttempts($request);
|
154
90
|
|
155
91
|
|
156
92
|
|
93
|
+
return $this->authenticated($request, $this->guard()->user())
|
94
|
+
|
157
|
-
|
95
|
+
?: redirect()->with('flash_message', 'ログインしました')->intended($this->redirectPath());
|
96
|
+
|
97
|
+
|
158
98
|
|
159
99
|
}
|
160
100
|
|
@@ -162,4 +102,14 @@
|
|
162
102
|
|
163
103
|
|
164
104
|
|
105
|
+
上記2つを試したのですが、ダメでした。。。。、
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
165
115
|
何か考えられる原因はありますでしょうか。。。
|