LoginSignup
0
0

【FormRequest】バリデーションエラー時に任意のURLにリダイレクト

Last updated at Posted at 2023-10-01

親クラスであるFormRequestクラスの「getRedirectUrl」をオーバライドして以下のようにTestファイル内に記述する。

protected function getRedirectUrl()
{
    return route('xxxxx.show', ['id' => $this->route('id'), '#commentArea']);
}

・ユースケース
詳細画面にコメント機能があり、コメントの入力でバリデーションエラーが起きた際にコメントエリアのアンカーリンク付きのURLにリダイレクトさせる時など。

0
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
0
0