久久久久久久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())
主站蜘蛛池模板: 日本成年免费网站 | 日韩在线一区二区三区 | 欧美一区二区网站 | 亚洲国产精品成人久久久 | 天天欧美 | 国产精品国产亚洲精品看不卡15 | 999免费观看视频 | 99re视频在线观看 | 日韩中文在线视频 | 精品国产乱码久久久久久牛牛 | 99re视频在线观看 | 亚洲精品日本 | 手机看片1 | 国产精品久久久久久久久久久免费看 | 免费久久99精品国产婷婷六月 | 91久久| 日韩中文字幕免费在线 | 国产精品久久精品 | 九九九色| 国产精品免费一区二区 | 国产2区 | 国产91丝袜在线播放 | 国产丝袜av | 国产精品久久久久久久久久了 | 国产日韩精品在线 | av综合站| 一级黄a视频 | 另类 综合 日韩 欧美 亚洲 | 自拍视频一区二区三区 | 国产精品亚洲精品久久 | 国产精品日韩高清伦字幕搜索 | 国产精品福利在线 | 91精品久久久久久综合五月天 | 亚洲久久久 | 午夜国产| 成人午夜免费在线视频 | www.日韩| 日韩精品1区2区 | 超碰伊人久久 | 精品视频www| 久久久久久久久久久91 |