質問編集履歴
2
情報の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -253,3 +253,439 @@
|
|
253
253
|
認証機能は独自のものではなくlaravel-uiを使用して作りましたが、マルチ認証のため[https://reffect.co.jp/laravel/laravel-multi-authentication-understand](https://reffect.co.jp/laravel/laravel-multi-authentication-understand)
|
254
254
|
|
255
255
|
こちらを参考に各ファイルは変更してあります。
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
追記
|
262
|
+
|
263
|
+
こちらが各controllerになります。リダイレクト先はRouteServiceProviderで指定しています。
|
264
|
+
|
265
|
+
```PHP
|
266
|
+
|
267
|
+
<?php
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
namespace App\Http\Controllers\Auth;
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
use App\Http\Controllers\Controller;
|
276
|
+
|
277
|
+
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
278
|
+
|
279
|
+
use App\Providers\RouteServiceProvider;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
class LoginController extends Controller
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
/*
|
288
|
+
|
289
|
+
|--------------------------------------------------------------------------
|
290
|
+
|
291
|
+
| Login Controller
|
292
|
+
|
293
|
+
|--------------------------------------------------------------------------
|
294
|
+
|
295
|
+
|
|
296
|
+
|
297
|
+
| This controller handles authenticating users for the application and
|
298
|
+
|
299
|
+
| redirecting them to your home screen. The controller uses a trait
|
300
|
+
|
301
|
+
| to conveniently provide its functionality to your applications.
|
302
|
+
|
303
|
+
|
|
304
|
+
|
305
|
+
*/
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
use AuthenticatesUsers;
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
/**
|
314
|
+
|
315
|
+
* Where to redirect users after login.
|
316
|
+
|
317
|
+
*
|
318
|
+
|
319
|
+
* @var string
|
320
|
+
|
321
|
+
*/
|
322
|
+
|
323
|
+
protected $redirectTo = RouteServiceProvider::HOME;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
/**
|
328
|
+
|
329
|
+
* Create a new controller instance.
|
330
|
+
|
331
|
+
*
|
332
|
+
|
333
|
+
* @return void
|
334
|
+
|
335
|
+
*/
|
336
|
+
|
337
|
+
public function __construct()
|
338
|
+
|
339
|
+
{
|
340
|
+
|
341
|
+
$this->middleware('guest')->except('logout');
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
```
|
350
|
+
|
351
|
+
```PHP
|
352
|
+
|
353
|
+
<?php
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
namespace App\Http\Controllers\Auth;
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
use App\User;
|
362
|
+
|
363
|
+
use App\Http\Controllers\Controller;
|
364
|
+
|
365
|
+
use Illuminate\Support\Facades\Hash;
|
366
|
+
|
367
|
+
use Illuminate\Support\Facades\Validator;
|
368
|
+
|
369
|
+
use Illuminate\Foundation\Auth\RegistersUsers;
|
370
|
+
|
371
|
+
use App\Providers\RouteServiceProvider;
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
class RegisterController extends Controller
|
376
|
+
|
377
|
+
{
|
378
|
+
|
379
|
+
/*
|
380
|
+
|
381
|
+
|--------------------------------------------------------------------------
|
382
|
+
|
383
|
+
| Register Controller
|
384
|
+
|
385
|
+
|--------------------------------------------------------------------------
|
386
|
+
|
387
|
+
|
|
388
|
+
|
389
|
+
| This controller handles the registration of new users as well as their
|
390
|
+
|
391
|
+
| validation and creation. By default this controller uses a trait to
|
392
|
+
|
393
|
+
| provide this functionality without requiring any additional code.
|
394
|
+
|
395
|
+
|
|
396
|
+
|
397
|
+
*/
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
use RegistersUsers;
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
/**
|
406
|
+
|
407
|
+
* Where to redirect users after registration.
|
408
|
+
|
409
|
+
*
|
410
|
+
|
411
|
+
* @var string
|
412
|
+
|
413
|
+
*/
|
414
|
+
|
415
|
+
protected $redirectTo = RouteServiceProvider::HOME;
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
/**
|
420
|
+
|
421
|
+
* Create a new controller instance.
|
422
|
+
|
423
|
+
*
|
424
|
+
|
425
|
+
* @return void
|
426
|
+
|
427
|
+
*/
|
428
|
+
|
429
|
+
public function __construct()
|
430
|
+
|
431
|
+
{
|
432
|
+
|
433
|
+
$this->middleware('guest');
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
/**
|
440
|
+
|
441
|
+
* Get a validator for an incoming registration request.
|
442
|
+
|
443
|
+
*
|
444
|
+
|
445
|
+
* @param array $data
|
446
|
+
|
447
|
+
* @return \Illuminate\Contracts\Validation\Validator
|
448
|
+
|
449
|
+
*/
|
450
|
+
|
451
|
+
protected function validator(array $data)
|
452
|
+
|
453
|
+
{
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
$validate = Validator::make($data, [
|
458
|
+
|
459
|
+
'screen_name' => ['required', 'string', 'max:255', 'unique:users'],
|
460
|
+
|
461
|
+
'name' => ['required', 'string', 'max:255'],
|
462
|
+
|
463
|
+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
464
|
+
|
465
|
+
'password' => ['required', 'string', 'min:6', 'confirmed'],
|
466
|
+
|
467
|
+
]);
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
//dd($validate->errors()->all());
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
return $validate;
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
/**
|
482
|
+
|
483
|
+
* Create a new user instance after a valid registration.
|
484
|
+
|
485
|
+
*
|
486
|
+
|
487
|
+
* @param array $data
|
488
|
+
|
489
|
+
* @return \App\User
|
490
|
+
|
491
|
+
*/
|
492
|
+
|
493
|
+
protected function create(array $data)
|
494
|
+
|
495
|
+
{
|
496
|
+
|
497
|
+
$count = \App\User::all()->count();
|
498
|
+
|
499
|
+
$count = $count + \App\Company::all()->count() +1;
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
$user= User::create([
|
504
|
+
|
505
|
+
'id' => $count,
|
506
|
+
|
507
|
+
'screen_name' => $data['screen_name'],
|
508
|
+
|
509
|
+
'name' => $data['name'],
|
510
|
+
|
511
|
+
'profile_image' => '/sample/user.png',
|
512
|
+
|
513
|
+
'back_image' => '/sample/noimage.jpg',
|
514
|
+
|
515
|
+
'email' => $data['email'],
|
516
|
+
|
517
|
+
'password' => Hash::make($data['password']),
|
518
|
+
|
519
|
+
]);
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
return $user;
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
}
|
528
|
+
|
529
|
+
}
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
```
|
534
|
+
|
535
|
+
```PHP
|
536
|
+
|
537
|
+
<?php
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
namespace App\Providers;
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
use Illuminate\Support\Facades\Route;
|
546
|
+
|
547
|
+
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
class RouteServiceProvider extends ServiceProvider
|
552
|
+
|
553
|
+
{
|
554
|
+
|
555
|
+
/**
|
556
|
+
|
557
|
+
* This namespace is applied to your controller routes.
|
558
|
+
|
559
|
+
*
|
560
|
+
|
561
|
+
* In addition, it is set as the URL generator's root namespace.
|
562
|
+
|
563
|
+
*
|
564
|
+
|
565
|
+
* @var string
|
566
|
+
|
567
|
+
*/
|
568
|
+
|
569
|
+
protected $namespace = 'App\Http\Controllers';
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
public const HOME = '/home';
|
574
|
+
|
575
|
+
public const COMPANIES_HOME = '/company/home';
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
/**
|
580
|
+
|
581
|
+
* Define your route model bindings, pattern filters, etc.
|
582
|
+
|
583
|
+
*
|
584
|
+
|
585
|
+
* @return void
|
586
|
+
|
587
|
+
*/
|
588
|
+
|
589
|
+
public function boot()
|
590
|
+
|
591
|
+
{
|
592
|
+
|
593
|
+
//
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
parent::boot();
|
598
|
+
|
599
|
+
}
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
/**
|
604
|
+
|
605
|
+
* Define the routes for the application.
|
606
|
+
|
607
|
+
*
|
608
|
+
|
609
|
+
* @return void
|
610
|
+
|
611
|
+
*/
|
612
|
+
|
613
|
+
public function map()
|
614
|
+
|
615
|
+
{
|
616
|
+
|
617
|
+
$this->mapApiRoutes();
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
$this->mapWebRoutes();
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
//
|
626
|
+
|
627
|
+
}
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
/**
|
632
|
+
|
633
|
+
* Define the "web" routes for the application.
|
634
|
+
|
635
|
+
*
|
636
|
+
|
637
|
+
* These routes all receive session state, CSRF protection, etc.
|
638
|
+
|
639
|
+
*
|
640
|
+
|
641
|
+
* @return void
|
642
|
+
|
643
|
+
*/
|
644
|
+
|
645
|
+
protected function mapWebRoutes()
|
646
|
+
|
647
|
+
{
|
648
|
+
|
649
|
+
Route::middleware('web')
|
650
|
+
|
651
|
+
->namespace($this->namespace)
|
652
|
+
|
653
|
+
->group(base_path('routes/web.php'));
|
654
|
+
|
655
|
+
}
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
/**
|
660
|
+
|
661
|
+
* Define the "api" routes for the application.
|
662
|
+
|
663
|
+
*
|
664
|
+
|
665
|
+
* These routes are typically stateless.
|
666
|
+
|
667
|
+
*
|
668
|
+
|
669
|
+
* @return void
|
670
|
+
|
671
|
+
*/
|
672
|
+
|
673
|
+
protected function mapApiRoutes()
|
674
|
+
|
675
|
+
{
|
676
|
+
|
677
|
+
Route::prefix('api')
|
678
|
+
|
679
|
+
->middleware('api')
|
680
|
+
|
681
|
+
->namespace($this->namespace)
|
682
|
+
|
683
|
+
->group(base_path('routes/api.php'));
|
684
|
+
|
685
|
+
}
|
686
|
+
|
687
|
+
}
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
```
|
1
追加の説明
test
CHANGED
File without changes
|
test
CHANGED
@@ -215,3 +215,41 @@
|
|
215
215
|
|
216
216
|
|
217
217
|
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
追記
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
phpバージョン
|
226
|
+
|
227
|
+
```ここに言語を入力
|
228
|
+
|
229
|
+
$ php -v
|
230
|
+
|
231
|
+
PHP 7.4.6 (cli) (built: May 12 2020 11:38:54) ( ZTS Visual C++ 2017 x64 )
|
232
|
+
|
233
|
+
Copyright (c) The PHP Group
|
234
|
+
|
235
|
+
Zend Engine v3.4.0, Copyright (c) Zend Technologies
|
236
|
+
|
237
|
+
```
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
Laravelバージョン
|
242
|
+
|
243
|
+
```ここに言語を入力
|
244
|
+
|
245
|
+
$ php artisan --version
|
246
|
+
|
247
|
+
Laravel Framework 7.0.0
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
認証機能は独自のものではなくlaravel-uiを使用して作りましたが、マルチ認証のため[https://reffect.co.jp/laravel/laravel-multi-authentication-understand](https://reffect.co.jp/laravel/laravel-multi-authentication-understand)
|
254
|
+
|
255
|
+
こちらを参考に各ファイルは変更してあります。
|