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

Laravel バリデーション

Posted at

required_with_all

:の後のカラム全てが入力されている場合にキーのカラムが必須になります。

つまり、以下のコードで考えると「cityとstateの両方が入力されている場合、addressは必須である」という意味になります。cityまたはstateのどちらかが入力されていない場合、addressは必須でなくなります。

$rules = [
    'address' => 'required_with_all:city,state',
    'city' => 'nullable|string',
    'state' => 'nullable|string',
];

他にも

  • required_if
  • required_with
  • required_without
    など
    便利なバリデーションがあるようです。
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?