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

帶有通配符的 Laravel 驗(yàn)證器

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

問題描述

我想制作一個(gè) Laravel 驗(yàn)證器來驗(yàn)證數(shù)組內(nèi)的未命名數(shù)組 ( 0,1,2,3 ) 內(nèi)的字段

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

所以我的數(shù)組就像

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

現(xiàn)在支持問題中的語法

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

Laravel 5.1

首先使用您的所有其他規(guī)則創(chuàng)建驗(yàn)證器.對(duì)項(xiàng)目使用 array 規(guī)則

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 方法將一組規(guī)則應(yīng)用于 items 數(shù)組中的每個(gè)項(xiàng)目.

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', 
]);

這將自動(dòng)為您設(shè)置這些規(guī)則...

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

這篇關(guān)于帶有通配符的 Laravel 驗(yàn)證器的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數(shù))
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數(shù)中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應(yīng)內(nèi)容必須是實(shí)現(xiàn) __toString()、“boolean和“boolean的字符串或?qū)ο?移動(dòng)到 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())
主站蜘蛛池模板: 久久999| 日韩在线一区二区 | 老司机午夜性大片 | 亚洲欧洲在线观看视频 | 九九综合九九 | 中文字幕 在线观看 | 亚洲精品一 | 青青草免费在线视频 | 久久久久久久久一区 | 欧美激情一区二区三区 | 欧美精品第一区 | 午夜免费视频 | 精品99久久久久久 | 婷婷久久网 | www.久| 欧美精品第一页 | 免费在线观看一区二区 | 国产精品一区二区视频 | 国产福利在线 | 亚洲一区二区三区国产 | 精产嫩模国品一二三区 | 日韩欧美在线播放 | 午夜精品一区二区三区免费视频 | 91国产精品 | 一区二区三区国产视频 | 欧美日韩视频一区二区 | 国产免费人成xvideos视频 | 国产伦精品一区二区三毛 | 麻豆精品久久 | 欧美一区二区三区在线观看视频 | 自拍 亚洲 欧美 老师 丝袜 | 日韩在线播放一区 | 99视频在线看 | 午夜精品一区二区三区在线观看 | 久久精品日产第一区二区三区 | 亚洲国产一区二区视频 | 欧美一区二区免费 | 欧美日韩专区 | 精品区| 五月天天丁香婷婷在线中 | 精品中文字幕在线观看 |