久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有通配符的 Laravel 驗證器

Laravel validator with a wildcard(帶有通配符的 Laravel 驗證器)
本文介紹了帶有通配符的 Laravel 驗證器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想制作一個 Laravel 驗證器來驗證數組內的未命名數組 ( 0,1,2,3 ) 內的字段

i want to make a laravel validator that validates the the fields inside an un-named array ( 0,1,2,3 ) that is inside an array

所以我的數組就像

array [ //the form data
  "items" => array:2 [ //the main array i want to validate
    0 => array:2 [ // the inner array that i want to validate its data
      "id" => "1"
      "quantity" => "1000"
     ]
    1 => array:2 [
     "id" => "1"
     "quantity" => "1000"
     ]
  // other fields of the form,
  ]

]

所以我想要的是像

  $validator = Validator::make($request->all(), [
     'items.*.id' => 'required' //notice the star *
  ]);

推薦答案

Laravel 5.2

現在支持問題中的語法

http://laravel.com/docs/master/validation#validating-arrays

Laravel 5.1

首先使用您的所有其他規則創建驗證器.對項目使用 array 規則

First create the validator with all of your other rules. Use the array rule for items

$validator = Validator::make($request->all(), [
    'items' => 'array',
    // your other rules here
]);

然后使用 Validator each 方法將一組規則應用于 items 數組中的每個項目.

Then use the Validator each method to apply a set of rules to every item in the items array.

$validator->each('items', [
    'id'       => 'required',
    'quantity' => 'min:0', 
]);

這將自動為您設置這些規則...

This will automatically set these rules for you...

items.*.id       => required
items.*.quantity => min:0

https://github.com/laravel/framework/blob/5.1/src/Illuminate/Validation/Validator.php#L261

這篇關于帶有通配符的 Laravel 驗證器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 男人天堂网址 | 三级成人片 | 日韩在线中文字幕 | 国产高清视频 | 日韩精品视频在线观看一区二区三区 | 日日摸日日添日日躁av | 国产精品1区2区3区 一区中文字幕 | 国产激情视频在线 | 日本久久网 | 亚洲欧美视频 | 做a的各种视频 | 国产精品1区2区3区 男女啪啪高潮无遮挡免费动态 | 伊人热久久 | 一区二区精品 | 国产精品自产av一区二区三区 | 拍真实国产伦偷精品 | 成年免费大片黄在线观看一级 | 精品久久久久久久久久久久久 | 欧美网址在线观看 | 国产综合久久久久久鬼色 | 午夜电影网 | 91婷婷韩国欧美一区二区 | 国产精品久久久乱弄 | 亚洲精品国产a久久久久久 午夜影院网站 | 日韩综合在线 | 精品真实国产乱文在线 | 久久久久久成人 | 久久av网站| 国产一区二区在线91 | 在线第一页| 亚洲一区二区成人 | 综合久久色 | 亚洲精品乱码久久久久久按摩观 | 亚洲综合一区二区三区 | 天天干天天插天天 | 久久久久久国产精品三区 | 欧美一级欧美三级在线观看 | av官网在线| 国内毛片毛片毛片毛片 | 性色av一区 | 久久精品视频亚洲 |