久久久久久久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())
主站蜘蛛池模板: 国产午夜精品视频 | 欧美成人精品欧美一级 | 国产亚洲一区二区精品 | 国产真实精品久久二三区 | 久久99精品久久久久久国产越南 | 污污免费网站 | 欧美成人一级视频 | 国产精品999 | 在线一区视频 | 国产精品永久免费观看 | 欧美激情视频一区二区三区免费 | 亚洲一区二区国产 | 亚洲国产情侣自拍 | 日韩精品在线看 | 精品欧美一区二区三区久久久 | 中文字幕一区二区三区精彩视频 | 在线久草| 久久草视频 | 国产成人叼嘿视频在线观看 | 国产成人免费视频网站高清观看视频 | 国产日韩欧美精品 | 亚洲精品一区二区在线观看 | 538在线精品 | 中文字幕第十页 | 免费一二区 | 9色视频在线 | 亚洲精品456| 国产欧美在线播放 | 成人在线视频网 | 日本免费在线看 | 国产一区二区在线91 | 一区二区三区在线 | 亚洲一二三区免费 | 九九伊人sl水蜜桃色推荐 | 亚洲精品66 | 国产在线一区观看 | 亚洲精品久久久久久久久久久 | 神马久久久久久久久久 | 欧美一卡二卡在线 | 亚洲第一视频网 | 在线视频一区二区三区 |