LoginSignup
8
7

More than 5 years have passed since last update.

Laravel5 FormRequestでエラー時のリダイレクト先を変更する

Posted at

よく直前の画面にリダイレクトされますと書いてありますが、
飛び先は任意の画面を指定できます。
入力→確認→登録というフローの時に、
確認画面をすっ飛ばして、入力←登録と戻したい時等に有効かと思います。

$redirectプロパティをオーバーライドすればOKです。

.
.
.

class StorePostRequest extends FormRequest
{ 
    // URL
    protected $redirect = 'posts/create';

    // or 名前付きURLでも可
    protected $redirectRoute = 'posts.create';

    // or コントローラーとアクションの指定でも可
    protected $redirectAction = 'PostsController@create';

    .
    .
    .
}
8
7
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
8
7