質問編集履歴
1
config/auth.phpのソースが間違ってたので変更しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,6 +72,156 @@
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
+
return [
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
'defaults' => [
|
82
|
+
|
83
|
+
'user' => [
|
84
|
+
|
85
|
+
'guard' => 'user',
|
86
|
+
|
87
|
+
'passwords' => 'users',
|
88
|
+
|
89
|
+
],
|
90
|
+
|
91
|
+
],
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
'guards' => [
|
98
|
+
|
99
|
+
// 'web' => [
|
100
|
+
|
101
|
+
// 'driver' => 'session',
|
102
|
+
|
103
|
+
// 'provider' => 'users',
|
104
|
+
|
105
|
+
// ],
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
'user' => [
|
110
|
+
|
111
|
+
'driver' => 'session',
|
112
|
+
|
113
|
+
'provider' => 'users',
|
114
|
+
|
115
|
+
],
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
'admin' => [
|
120
|
+
|
121
|
+
'driver' => 'session',
|
122
|
+
|
123
|
+
'provider' => 'admins',
|
124
|
+
|
125
|
+
],
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
'api' => [
|
130
|
+
|
131
|
+
'driver' => 'token',
|
132
|
+
|
133
|
+
'provider' => 'users',
|
134
|
+
|
135
|
+
'hash' => false,
|
136
|
+
|
137
|
+
],
|
138
|
+
|
139
|
+
],
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
'providers' => [
|
146
|
+
|
147
|
+
'users' => [
|
148
|
+
|
149
|
+
'driver' => 'eloquent',
|
150
|
+
|
151
|
+
'model' => App\Models\User::class,
|
152
|
+
|
153
|
+
],
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
'admins' => [
|
158
|
+
|
159
|
+
'driver' => 'eloquent',
|
160
|
+
|
161
|
+
'model' => App\Models\Admin::class,
|
162
|
+
|
163
|
+
]
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
],
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
'passwords' => [
|
172
|
+
|
173
|
+
'users' => [
|
174
|
+
|
175
|
+
'provider' => 'users',
|
176
|
+
|
177
|
+
'table' => 'password_resets',
|
178
|
+
|
179
|
+
'expire' => 60,
|
180
|
+
|
181
|
+
'throttle' => 60,
|
182
|
+
|
183
|
+
],
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
'admins' => [
|
188
|
+
|
189
|
+
'provider' => 'admins',
|
190
|
+
|
191
|
+
'table' => 'password_resets',
|
192
|
+
|
193
|
+
'expire' => 60,
|
194
|
+
|
195
|
+
'throttle' => 60,
|
196
|
+
|
197
|
+
]
|
198
|
+
|
199
|
+
],
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
'password_timeout' => 10800,
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
];
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
**Handler.php**
|
218
|
+
|
219
|
+
```PHP
|
220
|
+
|
221
|
+
<?php
|
222
|
+
|
223
|
+
|
224
|
+
|
75
225
|
namespace App\Exceptions;
|
76
226
|
|
77
227
|
|
@@ -176,15 +326,11 @@
|
|
176
326
|
|
177
327
|
|
178
328
|
|
179
|
-
|
180
|
-
|
181
|
-
```
|
329
|
+
```
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
330
|
+
|
331
|
+
|
332
|
+
|
187
|
-
**
|
333
|
+
**Route/web.php**
|
188
334
|
|
189
335
|
```PHP
|
190
336
|
|
@@ -192,105 +338,191 @@
|
|
192
338
|
|
193
339
|
|
194
340
|
|
341
|
+
use Illuminate\Support\Facades\Route;
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
Auth::routes();
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
// ユーザー
|
354
|
+
|
355
|
+
Route::namespace('User')->prefix('user')->name('user.')->group(function () {
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
// ログイン認証関連
|
360
|
+
|
361
|
+
Auth::routes([
|
362
|
+
|
363
|
+
'register' => true,
|
364
|
+
|
365
|
+
'reset' => false,
|
366
|
+
|
367
|
+
'verify' => false
|
368
|
+
|
369
|
+
]);
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
// ログイン認証後
|
374
|
+
|
375
|
+
Route::middleware('auth:user')->group(function () {
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
// TOPページ
|
380
|
+
|
381
|
+
Route::resource('home', 'HomeController', ['only' => 'index']);
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
});
|
386
|
+
|
387
|
+
});
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
// 管理者
|
392
|
+
|
393
|
+
Route::prefix('admin')->name('admin.')->group(function () {
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
// ログイン認証関連
|
398
|
+
|
399
|
+
Auth::routes([
|
400
|
+
|
401
|
+
'register' => true,
|
402
|
+
|
403
|
+
'reset' => false,
|
404
|
+
|
405
|
+
'verify' => false
|
406
|
+
|
407
|
+
]);
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
// ログイン認証後
|
412
|
+
|
413
|
+
Route::middleware('auth:admin')->group(function () {
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
// TOPページ
|
418
|
+
|
419
|
+
Route::resource('home', 'HomeController', ['only' => 'index']);
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
});
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
});
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
```
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
**管理者:LoginController.php**
|
438
|
+
|
439
|
+
```
|
440
|
+
|
441
|
+
<?php
|
442
|
+
|
443
|
+
|
444
|
+
|
195
|
-
namespace App\
|
445
|
+
namespace App\Http\Controllers\Admin\Auth;
|
196
|
-
|
197
|
-
|
198
|
-
|
446
|
+
|
447
|
+
|
448
|
+
|
199
|
-
use
|
449
|
+
use App\Http\Controllers\Controller;
|
450
|
+
|
200
|
-
|
451
|
+
use App\Providers\RouteServiceProvider;
|
452
|
+
|
201
|
-
use Illuminate\Auth\Authenticat
|
453
|
+
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
202
|
-
|
454
|
+
|
203
|
-
use
|
455
|
+
use Illuminate\Http\Request;
|
456
|
+
|
204
|
-
|
457
|
+
use Illuminate\Support\Facades\Auth;
|
205
|
-
|
206
|
-
|
458
|
+
|
459
|
+
|
460
|
+
|
207
|
-
class
|
461
|
+
class LoginController extends Controller
|
208
462
|
|
209
463
|
{
|
210
464
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
p
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
'
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
public function handle($request, Closure $next, $guard = null)
|
276
|
-
|
277
|
-
{
|
278
|
-
|
279
|
-
if (Auth::guard($guard)->check() && $guard === 'user') {
|
280
|
-
|
281
|
-
return redirect(RouteServiceProvider::HOME);
|
282
|
-
|
283
|
-
} elseif (Auth::guard($guard)->check() && $guard === 'admin') {
|
284
|
-
|
285
|
-
return redirect(RouteServiceProvider::ADMIN_HOME);
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
return $next($request);
|
292
|
-
|
293
|
-
}
|
465
|
+
use AuthenticatesUsers;
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
protected $redirectTo = RouteServiceProvider::ADMIN_HOME;
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
public function __construct()
|
474
|
+
|
475
|
+
{
|
476
|
+
|
477
|
+
$this->middleware('guest:admin')->except('logout');
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
protected function guard()
|
484
|
+
|
485
|
+
{
|
486
|
+
|
487
|
+
return Auth::guard('admin');
|
488
|
+
|
489
|
+
}
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
public function showLoginForm()
|
494
|
+
|
495
|
+
{
|
496
|
+
|
497
|
+
return view('admin.auth.login');
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
public function logout(Request $request)
|
504
|
+
|
505
|
+
{
|
506
|
+
|
507
|
+
Auth::guard('admin')->logout();
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
return $this->loggedOut($request);
|
512
|
+
|
513
|
+
}
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
public function loggedOut(Request $request)
|
518
|
+
|
519
|
+
{
|
520
|
+
|
521
|
+
return redirect(route('admin.login'));
|
522
|
+
|
523
|
+
}
|
524
|
+
|
525
|
+
|
294
526
|
|
295
527
|
}
|
296
528
|
|
@@ -300,141 +532,13 @@
|
|
300
532
|
|
301
533
|
|
302
534
|
|
303
|
-
**
|
535
|
+
**ユーザー:LoginController.php**
|
304
|
-
|
536
|
+
|
305
|
-
```
|
537
|
+
```
|
306
538
|
|
307
539
|
<?php
|
308
540
|
|
309
|
-
|
310
|
-
|
311
|
-
use Illuminate\Support\Facades\Route;
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
/*
|
316
|
-
|
317
|
-
|--------------------------------------------------------------------------
|
318
|
-
|
319
|
-
| Web Routes
|
320
|
-
|
321
|
-
|--------------------------------------------------------------------------
|
322
|
-
|
323
|
-
|
|
324
|
-
|
325
|
-
| Here is where you can register web routes for your application. These
|
326
|
-
|
327
|
-
| routes are loaded by the RouteServiceProvider within a group which
|
328
|
-
|
329
|
-
| contains the "web" middleware group. Now create something great!
|
330
|
-
|
331
|
-
|
|
332
|
-
|
333
|
-
*/
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
Auth::routes();
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
// ユーザー
|
346
|
-
|
347
|
-
Route::namespace('User')->prefix('user')->name('user.')->group(function () {
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
// ログイン認証関連
|
352
|
-
|
353
|
-
Auth::routes([
|
354
|
-
|
355
|
-
'register' => true,
|
356
|
-
|
357
|
-
'reset' => false,
|
358
|
-
|
359
|
-
'verify' => false
|
360
|
-
|
361
|
-
]);
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
// ログイン認証後
|
366
|
-
|
367
|
-
Route::middleware('auth:user')->group(function () {
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
// TOPページ
|
372
|
-
|
373
|
-
Route::resource('home', 'HomeController', ['only' => 'index']);
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
});
|
378
|
-
|
379
|
-
});
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
// 管理者
|
384
|
-
|
385
|
-
Route::prefix('admin')->name('admin.')->group(function () {
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
// ログイン認証関連
|
390
|
-
|
391
|
-
Auth::routes([
|
392
|
-
|
393
|
-
'register' => true,
|
394
|
-
|
395
|
-
'reset' => false,
|
396
|
-
|
397
|
-
'verify' => false
|
398
|
-
|
399
|
-
]);
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
// ログイン認証後
|
404
|
-
|
405
|
-
Route::middleware('auth:admin')->group(function () {
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
// TOPページ
|
410
|
-
|
411
|
-
Route::resource('home', 'HomeController', ['only' => 'index']);
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
});
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
});
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
```
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
**管理者:LoginController.php**
|
430
|
-
|
431
|
-
```
|
432
|
-
|
433
|
-
<?php
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
namespace App\Http\Controllers\A
|
541
|
+
namespace App\Http\Controllers\Auth;
|
438
542
|
|
439
543
|
|
440
544
|
|
@@ -458,7 +562,7 @@
|
|
458
562
|
|
459
563
|
|
460
564
|
|
461
|
-
protected $redirectTo = RouteServiceProvider::
|
565
|
+
protected $redirectTo = RouteServiceProvider::HOME;
|
462
566
|
|
463
567
|
|
464
568
|
|
@@ -466,37 +570,43 @@
|
|
466
570
|
|
467
571
|
{
|
468
572
|
|
469
|
-
$this->middleware('guest:
|
573
|
+
$this->middleware('guest:user')->except('logout');
|
470
|
-
|
574
|
+
|
471
|
-
}
|
575
|
+
}
|
576
|
+
|
577
|
+
|
578
|
+
|
472
|
-
|
579
|
+
// Guardの認証方法を指定
|
473
|
-
|
474
580
|
|
475
581
|
protected function guard()
|
476
582
|
|
477
583
|
{
|
478
584
|
|
479
|
-
return Auth::guard('
|
585
|
+
return Auth::guard('user');
|
480
|
-
|
586
|
+
|
481
|
-
}
|
587
|
+
}
|
588
|
+
|
589
|
+
|
590
|
+
|
482
|
-
|
591
|
+
// ログイン画面
|
483
|
-
|
484
592
|
|
485
593
|
public function showLoginForm()
|
486
594
|
|
487
595
|
{
|
488
596
|
|
489
|
-
return view('a
|
597
|
+
return view('auth.login');
|
490
|
-
|
598
|
+
|
491
|
-
}
|
599
|
+
}
|
600
|
+
|
601
|
+
|
602
|
+
|
492
|
-
|
603
|
+
// ログアウト処理
|
493
|
-
|
494
604
|
|
495
605
|
public function logout(Request $request)
|
496
606
|
|
497
607
|
{
|
498
608
|
|
499
|
-
Auth::guard('
|
609
|
+
Auth::guard('user')->logout();
|
500
610
|
|
501
611
|
|
502
612
|
|
@@ -506,15 +616,15 @@
|
|
506
616
|
|
507
617
|
|
508
618
|
|
619
|
+
// ログアウトした時のリダイレクト先
|
620
|
+
|
509
621
|
public function loggedOut(Request $request)
|
510
622
|
|
511
623
|
{
|
512
624
|
|
513
|
-
return redirect(route('
|
625
|
+
return redirect(route('user.login'));
|
514
|
-
|
626
|
+
|
515
|
-
}
|
627
|
+
}
|
516
|
-
|
517
|
-
|
518
628
|
|
519
629
|
}
|
520
630
|
|
@@ -524,108 +634,6 @@
|
|
524
634
|
|
525
635
|
|
526
636
|
|
527
|
-
**ユーザー:LoginController.php**
|
528
|
-
|
529
|
-
```
|
530
|
-
|
531
|
-
<?php
|
532
|
-
|
533
|
-
namespace App\Http\Controllers\Auth;
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
use App\Http\Controllers\Controller;
|
538
|
-
|
539
|
-
use App\Providers\RouteServiceProvider;
|
540
|
-
|
541
|
-
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
542
|
-
|
543
|
-
use Illuminate\Http\Request;
|
544
|
-
|
545
|
-
use Illuminate\Support\Facades\Auth;
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
class LoginController extends Controller
|
550
|
-
|
551
|
-
{
|
552
|
-
|
553
|
-
use AuthenticatesUsers;
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
protected $redirectTo = RouteServiceProvider::HOME;
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
public function __construct()
|
562
|
-
|
563
|
-
{
|
564
|
-
|
565
|
-
$this->middleware('guest:user')->except('logout');
|
566
|
-
|
567
|
-
}
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
// Guardの認証方法を指定
|
572
|
-
|
573
|
-
protected function guard()
|
574
|
-
|
575
|
-
{
|
576
|
-
|
577
|
-
return Auth::guard('user');
|
578
|
-
|
579
|
-
}
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
// ログイン画面
|
584
|
-
|
585
|
-
public function showLoginForm()
|
586
|
-
|
587
|
-
{
|
588
|
-
|
589
|
-
return view('auth.login');
|
590
|
-
|
591
|
-
}
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
// ログアウト処理
|
596
|
-
|
597
|
-
public function logout(Request $request)
|
598
|
-
|
599
|
-
{
|
600
|
-
|
601
|
-
Auth::guard('user')->logout();
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
return $this->loggedOut($request);
|
606
|
-
|
607
|
-
}
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
// ログアウトした時のリダイレクト先
|
612
|
-
|
613
|
-
public function loggedOut(Request $request)
|
614
|
-
|
615
|
-
{
|
616
|
-
|
617
|
-
return redirect(route('user.login'));
|
618
|
-
|
619
|
-
}
|
620
|
-
|
621
|
-
}
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
```
|
626
|
-
|
627
|
-
|
628
|
-
|
629
637
|
管理者ビュー:
|
630
638
|
|
631
639
|
```
|