2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel8 Jetstream アカウント作成後のリダイレクト先変更

Last updated at Posted at 2021-08-27

##はじめに
今回は、Laravel8でアカウント作成後のリダイレクト先を変更する方法についてご紹介します!
また、ログイン後のリダイレクト先変更については、こちらの記事で紹介していますので是非参考にしてください。
https://qiita.com/yyy752/items/60511e1ef799f9943ee7

リダイレクト先変更

1.RegisterResponseを新規作成。

/app/Http/Responses/RegisterResponse.php
<?php

namespace App\Http\Responses;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;

class RegisterResponse implements RegisterResponseContract
{        
    public function toResponse($request)
    {
        // below is the existing response
        // replace this with your own code

        return $request->wantsJson()
                    ? new JsonResponse('', 201)
                    : redirect('/list');
    }
}

2.JetstreamServiceProviderのbootを修正。

/app/Providers/JetstreamServiceProvider.php

    public function boot()
    {
        $this->configurePermissions();

        Jetstream::deleteUsersUsing(DeleteUser::class);

        // register new RegisterResponse
        $this->app->singleton(
            \Laravel\Fortify\Contracts\RegisterResponse::class,
            \App\Http\Responses\RegisterResponse::class
        );
    }

まとめ

以上でアカウント作成後のリダイレクト先を変更できました!
是非参考にしてみてください!

##参考サイト

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?