質問編集履歴

3

画像追加

2020/09/01 14:12

投稿

chocomint20
chocomint20

スコア1

test CHANGED
@@ -1 +1 @@
1
- Laravelで新規登録後に画面遷移しない問題
1
+ Laravelで新規ユーザー登録後に画面遷移しない問題
test CHANGED
@@ -671,3 +671,9 @@
671
671
 
672
672
 
673
673
  上記のことを試しても挙動が変わりませんでした。自分で調べれる限りは試してみたのですがエラーも出ていないしさっぱり原因がわかりません。他に考えうる原因はあるのでしょうか?
674
+
675
+
676
+
677
+ ちなみに下記画像のように遷移先のURLはGETでResponseがちゃんと返ってきています
678
+
679
+ ![イメージ説明](efe18faa1902feace0612f1380dae4a1.png)

2

自分で試したことを追記しました。

2020/09/01 14:12

投稿

chocomint20
chocomint20

スコア1

test CHANGED
File without changes
test CHANGED
@@ -611,3 +611,63 @@
611
611
  </script>
612
612
 
613
613
  ```
614
+
615
+
616
+
617
+
618
+
619
+ **追記(試したこと)**
620
+
621
+ ①RegisterController.phpの
622
+
623
+ ```
624
+
625
+ protected $redirectTo = '/home';
626
+
627
+ ```
628
+
629
+ これを
630
+
631
+ ```
632
+
633
+ protected $redirectTo = '/mypage/profile';
634
+
635
+ ```
636
+
637
+ これに変えた。
638
+
639
+
640
+
641
+ ②RegisterController.phpに
642
+
643
+ ```
644
+
645
+ protected function redirectTo()
646
+
647
+ {
648
+
649
+ return route('mypage.prof');
650
+
651
+ }
652
+
653
+ ```
654
+
655
+ 上記のredirectToメソッドを作成
656
+
657
+
658
+
659
+
660
+
661
+ ③ブラウザをChromeでやっていたので、safariに変えてみた
662
+
663
+
664
+
665
+ ④vagrantとhomesteadでサーバーを立ててやっていたので、php artisan serveの方でやってみた
666
+
667
+
668
+
669
+ ⑤php artisan キャッシュクリア系のコマンドでキャッシュクリアしてみた
670
+
671
+
672
+
673
+ 上記のことを試しても挙動が変わりませんでした。自分で調べれる限りは試してみたのですがエラーも出ていないしさっぱり原因がわかりません。他に考えうる原因はあるのでしょうか?

1

訂正

2020/09/01 13:59

投稿

chocomint20
chocomint20

スコア1

test CHANGED
File without changes
test CHANGED
@@ -140,382 +140,472 @@
140
140
 
141
141
  ```
142
142
 
143
- public function auth(array $options = [])
144
-
145
- {
146
-
147
- // Authentication Routes...
148
-
149
- $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
150
-
151
- $this->post('login', 'Auth\LoginController@login');
152
-
153
- $this->get('logout', 'Auth\LoginController@showLogout')->name('logout');
154
-
155
- $this->post('logout', 'Auth\LoginController@logout');
156
-
157
-
158
-
159
- // Registration Routes...
160
-
161
- if ($options['register'] ?? true) {
162
-
163
- $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
164
-
165
- $this->post('register', 'Auth\RegisterController@register');
143
+ <?php
144
+
145
+
146
+
147
+ namespace App\Http\Controllers\Auth;
148
+
149
+
150
+
151
+ use App\User;
152
+
153
+ use App\Http\Controllers\Controller;
154
+
155
+ use Illuminate\Support\Facades\Hash;
156
+
157
+ use Illuminate\Support\Facades\Validator;
158
+
159
+ use Illuminate\Foundation\Auth\RegistersUsers;
160
+
161
+
162
+
163
+ class RegisterController extends Controller
164
+
165
+ {
166
+
167
+ /*
168
+
169
+ |--------------------------------------------------------------------------
170
+
171
+ | Register Controller
172
+
173
+ |--------------------------------------------------------------------------
174
+
175
+ |
176
+
177
+ | This controller handles the registration of new users as well as their
178
+
179
+ | validation and creation. By default this controller uses a trait to
180
+
181
+ | provide this functionality without requiring any additional code.
182
+
183
+ |
184
+
185
+ */
186
+
187
+
188
+
189
+ use RegistersUsers;
190
+
191
+
192
+
193
+ /**
194
+
195
+ * Where to redirect users after registration.
196
+
197
+ *
198
+
199
+ * @var string
200
+
201
+ */
202
+
203
+ protected $redirectTo = '/mypage/profile';
204
+
205
+
206
+
207
+ /**
208
+
209
+ * Create a new controller instance.
210
+
211
+ *
212
+
213
+ * @return void
214
+
215
+ */
216
+
217
+ public function __construct()
218
+
219
+ {
220
+
221
+ $this->middleware('guest');
222
+
223
+ }
224
+
225
+
226
+
227
+ /**
228
+
229
+ * Get a validator for an incoming registration request.
230
+
231
+ *
232
+
233
+ * @param array $data
234
+
235
+ * @return \Illuminate\Contracts\Validation\Validator
236
+
237
+ */
238
+
239
+ protected function validator(array $data)
240
+
241
+ {
242
+
243
+ return Validator::make($data, [
244
+
245
+ 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
246
+
247
+ 'password' => ['required', 'string', 'min:6',],
248
+
249
+ ]);
250
+
251
+ }
252
+
253
+
254
+
255
+ /**
256
+
257
+ * Create a new user instance after a valid registration.
258
+
259
+ *
260
+
261
+ * @param array $data
262
+
263
+ * @return \App\User
264
+
265
+ */
266
+
267
+ protected function create(array $data)
268
+
269
+ {
270
+
271
+ return User::create([
272
+
273
+ 'email' => $data['email'],
274
+
275
+ 'password' => Hash::make($data['password']),
276
+
277
+ ]);
278
+
279
+ }
280
+
281
+ }
282
+
283
+
284
+
285
+ ```
286
+
287
+
288
+
289
+ **RegistersUsers.php**
290
+
291
+ ```
292
+
293
+ <?php
294
+
295
+
296
+
297
+ namespace Illuminate\Foundation\Auth;
298
+
299
+
300
+
301
+ use Illuminate\Http\Request;
302
+
303
+ use Illuminate\Support\Facades\Auth;
304
+
305
+ use Illuminate\Auth\Events\Registered;
306
+
307
+
308
+
309
+ trait RegistersUsers
310
+
311
+ {
312
+
313
+ use RedirectsUsers;
314
+
315
+
316
+
317
+ /**
318
+
319
+ * Show the application registration form.
320
+
321
+ *
322
+
323
+ * @return \Illuminate\Http\Response
324
+
325
+ */
326
+
327
+ public function showRegistrationForm()
328
+
329
+ {
330
+
331
+ return view('auth.register');
332
+
333
+ }
334
+
335
+
336
+
337
+ /**
338
+
339
+ * Handle a registration request for the application.
340
+
341
+ *
342
+
343
+ * @param \Illuminate\Http\Request $request
344
+
345
+ * @return \Illuminate\Http\Response
346
+
347
+ */
348
+
349
+ public function register(Request $request)
350
+
351
+ {
352
+
353
+ $this->validator($request->all())->validate();
354
+
355
+
356
+
357
+ event(new Registered($user = $this->create($request->all())));
358
+
359
+
360
+
361
+ $this->guard()->login($user);
362
+
363
+
364
+
365
+ return $this->registered($request, $user)
366
+
367
+ ?: redirect($this->redirectPath());
368
+
369
+
370
+
371
+ }
372
+
373
+
374
+
375
+ /**
376
+
377
+ * Get the guard to be used during registration.
378
+
379
+ *
380
+
381
+ * @return \Illuminate\Contracts\Auth\StatefulGuard
382
+
383
+ */
384
+
385
+ protected function guard()
386
+
387
+ {
388
+
389
+ return Auth::guard();
390
+
391
+ }
392
+
393
+
394
+
395
+ /**
396
+
397
+ * The user has been registered.
398
+
399
+ *
400
+
401
+ * @param \Illuminate\Http\Request $request
402
+
403
+ * @param mixed $user
404
+
405
+ * @return mixed
406
+
407
+ */
408
+
409
+ protected function registered(Request $request, $user)
410
+
411
+ {
412
+
413
+ //
414
+
415
+ }
416
+
417
+
418
+
419
+ }
420
+
421
+
422
+
423
+ ```
424
+
425
+
426
+
427
+ **register.blade.php**
428
+
429
+ ```
430
+
431
+ @extends('layouts.app2')
432
+
433
+
434
+
435
+ @section('title', '会員登録')
436
+
437
+
438
+
439
+ @section('content')
440
+
441
+ <div id="app">
442
+
443
+ <user-register></user-register>
444
+
445
+ </div>
446
+
447
+ @endsection
448
+
449
+ ```
450
+
451
+
452
+
453
+ **UserRegister.vue**
454
+
455
+ ```
456
+
457
+ <template>
458
+
459
+ <div class="l-form p-form">
460
+
461
+ <h2 class="l-form__head p-form__head">
462
+
463
+ 新規会員登録
464
+
465
+ </h2>
466
+
467
+
468
+
469
+ <div class="l-form__body p-form__body">
470
+
471
+ <div class="l-form-conteiner">
472
+
473
+ <div class="form-group">
474
+
475
+ <label for="email" class="l-form__label p-form__label">メールアドレス</label>
476
+
477
+ <span class="label-require">必須</span>
478
+
479
+ <input id="email" class="l-form__input p-form__input" :class="{ hasErr: errors.email }" type="text" v-model="email" placeholder="PC・携帯どちらでも可">
480
+
481
+ <div class="area-msg">
482
+
483
+ {{ errors.email }}
484
+
485
+ </div>
486
+
487
+ </div>
488
+
489
+
490
+
491
+
492
+
493
+ <div class="form-group">
494
+
495
+ <label for="password" class="l-form__label p-form__label">パスワード</label>
496
+
497
+ <span class="label-require">必須</span>
498
+
499
+ <input id="password" class="l-form__input p-form__input" :class="{ hasErr: errors.password }" type="password" v-model="password" placeholder="6文字以上の半角英数字">
500
+
501
+ <div class="area-msg">
502
+
503
+ {{ errors.password }}
504
+
505
+ </div>
506
+
507
+ </div>
508
+
509
+
510
+
511
+ <button type="button" class="p-btn btn-primary" @click="register">登録する</button>
512
+
513
+ </div>
514
+
515
+ </div>
516
+
517
+ </div>
518
+
519
+ </template>
520
+
521
+
522
+
523
+ <script>
524
+
525
+ export default {
526
+
527
+ data: function() {
528
+
529
+ return {
530
+
531
+ email: '',
532
+
533
+ password: '',
534
+
535
+ errors: ''
536
+
537
+ }
538
+
539
+ },
540
+
541
+ methods: {
542
+
543
+ register: function () {
544
+
545
+
546
+
547
+ this.errors = {};
548
+
549
+
550
+
551
+ var self = this;
552
+
553
+ var url = '/register';
554
+
555
+ var params = {
556
+
557
+ email: this.email,
558
+
559
+ password: this.password,
560
+
561
+ };
562
+
563
+ axios.post(url, params)
564
+
565
+ .then(function (response) {
566
+
567
+ self.email = '';
568
+
569
+ self.password = '';
570
+
571
+ })
572
+
573
+ .catch(function (error) {
574
+
575
+
576
+
577
+ var responseErrors = error.response.data.errors;
578
+
579
+ var errors = {};
580
+
581
+
582
+
583
+ for(var key in responseErrors) {
584
+
585
+
586
+
587
+ errors[key] = responseErrors[key][0];
588
+
589
+
590
+
591
+ }
592
+
593
+
594
+
595
+ self.errors = errors;
596
+
597
+ });
598
+
599
+ }
600
+
601
+ },
602
+
603
+ mounted() {
604
+
605
+ console.log('Component mounted.')
166
606
 
167
607
  }
168
608
 
169
- $this->get('withdraw', 'Auth\RegisterController@showWithdraw')->name('withdraw');
170
-
171
-
172
-
173
-
174
-
175
- // Password Reset Routes...
176
-
177
- if ($options['reset'] ?? true) {
178
-
179
- $this->resetPassword();
180
-
181
- }
182
-
183
-
184
-
185
- // Email Verification Routes...
186
-
187
- if ($options['verify'] ?? false) {
188
-
189
- $this->emailVerification();
190
-
191
- }
192
-
193
- }
194
-
195
- ```
196
-
197
-
198
-
199
- **RegistersUsers.php**
200
-
201
- ```
202
-
203
- <?php
204
-
205
-
206
-
207
- namespace Illuminate\Foundation\Auth;
208
-
209
-
210
-
211
- use Illuminate\Http\Request;
212
-
213
- use Illuminate\Support\Facades\Auth;
214
-
215
- use Illuminate\Auth\Events\Registered;
216
-
217
-
218
-
219
- trait RegistersUsers
220
-
221
- {
222
-
223
- use RedirectsUsers;
224
-
225
-
226
-
227
- /**
228
-
229
- * Show the application registration form.
230
-
231
- *
232
-
233
- * @return \Illuminate\Http\Response
234
-
235
- */
236
-
237
- public function showRegistrationForm()
238
-
239
- {
240
-
241
- return view('auth.register');
242
-
243
- }
244
-
245
-
246
-
247
- /**
248
-
249
- * Handle a registration request for the application.
250
-
251
- *
252
-
253
- * @param \Illuminate\Http\Request $request
254
-
255
- * @return \Illuminate\Http\Response
256
-
257
- */
258
-
259
- public function register(Request $request)
260
-
261
- {
262
-
263
- $this->validator($request->all())->validate();
264
-
265
-
266
-
267
- event(new Registered($user = $this->create($request->all())));
268
-
269
-
270
-
271
- $this->guard()->login($user);
272
-
273
-
274
-
275
- return $this->registered($request, $user)
276
-
277
- ?: redirect($this->redirectPath());
278
-
279
-
280
-
281
- }
282
-
283
-
284
-
285
- /**
286
-
287
- * Get the guard to be used during registration.
288
-
289
- *
290
-
291
- * @return \Illuminate\Contracts\Auth\StatefulGuard
292
-
293
- */
294
-
295
- protected function guard()
296
-
297
- {
298
-
299
- return Auth::guard();
300
-
301
- }
302
-
303
-
304
-
305
- /**
306
-
307
- * The user has been registered.
308
-
309
- *
310
-
311
- * @param \Illuminate\Http\Request $request
312
-
313
- * @param mixed $user
314
-
315
- * @return mixed
316
-
317
- */
318
-
319
- protected function registered(Request $request, $user)
320
-
321
- {
322
-
323
- //
324
-
325
- }
326
-
327
-
328
-
329
- }
330
-
331
-
332
-
333
- ```
334
-
335
-
336
-
337
- **register.blade.php**
338
-
339
- ```
340
-
341
- @extends('layouts.app2')
342
-
343
-
344
-
345
- @section('title', '会員登録')
346
-
347
-
348
-
349
- @section('content')
350
-
351
- <div id="app">
352
-
353
- <user-register></user-register>
354
-
355
- </div>
356
-
357
- @endsection
358
-
359
- ```
360
-
361
-
362
-
363
- **UserRegister.vue**
364
-
365
- ```
366
-
367
- <template>
368
-
369
- <div class="l-form p-form">
370
-
371
- <h2 class="l-form__head p-form__head">
372
-
373
- 新規会員登録
374
-
375
- </h2>
376
-
377
-
378
-
379
- <div class="l-form__body p-form__body">
380
-
381
- <div class="l-form-conteiner">
382
-
383
- <div class="form-group">
384
-
385
- <label for="email" class="l-form__label p-form__label">メールアドレス</label>
386
-
387
- <span class="label-require">必須</span>
388
-
389
- <input id="email" class="l-form__input p-form__input" :class="{ hasErr: errors.email }" type="text" v-model="email" placeholder="PC・携帯どちらでも可">
390
-
391
- <div class="area-msg">
392
-
393
- {{ errors.email }}
394
-
395
- </div>
396
-
397
- </div>
398
-
399
-
400
-
401
-
402
-
403
- <div class="form-group">
404
-
405
- <label for="password" class="l-form__label p-form__label">パスワード</label>
406
-
407
- <span class="label-require">必須</span>
408
-
409
- <input id="password" class="l-form__input p-form__input" :class="{ hasErr: errors.password }" type="password" v-model="password" placeholder="6文字以上の半角英数字">
410
-
411
- <div class="area-msg">
412
-
413
- {{ errors.password }}
414
-
415
- </div>
416
-
417
- </div>
418
-
419
-
420
-
421
- <button type="button" class="p-btn btn-primary" @click="register">登録する</button>
422
-
423
- </div>
424
-
425
- </div>
426
-
427
- </div>
428
-
429
- </template>
430
-
431
-
432
-
433
- <script>
434
-
435
- export default {
436
-
437
- data: function() {
438
-
439
- return {
440
-
441
- email: '',
442
-
443
- password: '',
444
-
445
- errors: ''
446
-
447
- }
448
-
449
- },
450
-
451
- methods: {
452
-
453
- register: function () {
454
-
455
-
456
-
457
- this.errors = {};
458
-
459
-
460
-
461
- var self = this;
462
-
463
- var url = '/register';
464
-
465
- var params = {
466
-
467
- email: this.email,
468
-
469
- password: this.password,
470
-
471
- };
472
-
473
- axios.post(url, params)
474
-
475
- .then(function (response) {
476
-
477
- self.email = '';
478
-
479
- self.password = '';
480
-
481
- })
482
-
483
- .catch(function (error) {
484
-
485
-
486
-
487
- var responseErrors = error.response.data.errors;
488
-
489
- var errors = {};
490
-
491
-
492
-
493
- for(var key in responseErrors) {
494
-
495
-
496
-
497
- errors[key] = responseErrors[key][0];
498
-
499
-
500
-
501
- }
502
-
503
-
504
-
505
- self.errors = errors;
506
-
507
- });
508
-
509
- }
510
-
511
- },
512
-
513
- mounted() {
514
-
515
- console.log('Component mounted.')
516
-
517
- }
518
-
519
609
  }
520
610
 
521
611
  </script>