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オブジェクト配列のバリデーション

Last updated at Posted at 2024-02-06

やりたいこと

このようなオブジェクトをもつ配列のバリデーション

{
    "hoge": [
        {
            "id": 1,
            "value": 2
        }
    ]
}
  • hogeは配列
  • id,valueは必須、integer
    としたい

結論

FormRequest
public function rules(): array
    {
        return [
            "hoge"  => ['required', 'array'],
            'hoge.*.id' => ['required', 'integer'],
            'hoge.*.value' => ['required', 'integer']
        ];
    }

id,value以外のプロパティがきたらエラーとなる。

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?