laravel-validation

can be nullable and must be unique validation in laravel

余生颓废 提交于 2021-02-11 12:33:27
问题 $this->validate($request, [ 'id_num' => 'required | unique:users', //this should be nullable not required with unique. ]); Is it possible to nullable + unique at a time? then what will be the procedures? 回答1: Simply remove the required from the validator. Is it possible to nullable + unique at a time? Yes then what will be the procedures? You don't need a procedure, declare the field as unique in the table migration. $table->unique('id_num')->nullable(); then your validator must look like:

How to get array index in validation message Laravel 5.2

人走茶凉 提交于 2021-02-07 08:37:39
问题 These arrays I put into Laravel Validator as arguments: ['item.*' => 'string'] // rules ['item.*.string' => 'Item number (index) is not string'] // messages I want to have index number in validation message. Code above is just for demonstration and does not work. How to do this? 回答1: Try this or use this one 'name' : [ { 'value' : 'raju' } , { 'value' : 'rani'} ] and validate it by 'name.*' or 'name.*.value' => 'required|string|min:5' The message will be 'name.*.required' => 'The :attribute

How to get array index in validation message Laravel 5.2

浪子不回头ぞ 提交于 2021-02-07 08:37:02
问题 These arrays I put into Laravel Validator as arguments: ['item.*' => 'string'] // rules ['item.*.string' => 'Item number (index) is not string'] // messages I want to have index number in validation message. Code above is just for demonstration and does not work. How to do this? 回答1: Try this or use this one 'name' : [ { 'value' : 'raju' } , { 'value' : 'rani'} ] and validate it by 'name.*' or 'name.*.value' => 'required|string|min:5' The message will be 'name.*.required' => 'The :attribute

Laravel validation for arrays

99封情书 提交于 2021-01-04 11:53:37
问题 I have this request: GET http://example.com/test?q[]=1&q[]=2&q[]=3 And I have this route: Route::get('test', function(Request $req) { $req->validate(['q' => 'array']); }); How should I do to add other validation rules to each element of this array using Laravel validator? For example, I want to check that each q value has a minimum of 2. Thank you for your help. 回答1: Take a look at the documentation about validating arrays. $validator = Validator::make($request->all(), [ 'person.*.email' =>

Validating array - get current iteration

笑着哭i 提交于 2020-07-21 02:40:49
问题 I'm trying to validate a POST request using Laravel's FormRequest . The customer is submitting an order, which has an array of items. We are requiring the user to indicate whether the item needs special_delivery only if the asking_price > 500 and the quantity > 10 . The following are my intended rules: public function rules() { 'customer_id' => 'required|integer|exists:customers,id', 'items' => 'required|array', 'items.*.name' => 'required|string', 'items.*.asking_price' => 'required|numeric'

Validating array - get current iteration

冷暖自知 提交于 2020-07-21 02:39:25
问题 I'm trying to validate a POST request using Laravel's FormRequest . The customer is submitting an order, which has an array of items. We are requiring the user to indicate whether the item needs special_delivery only if the asking_price > 500 and the quantity > 10 . The following are my intended rules: public function rules() { 'customer_id' => 'required|integer|exists:customers,id', 'items' => 'required|array', 'items.*.name' => 'required|string', 'items.*.asking_price' => 'required|numeric'

Validating array - get current iteration

丶灬走出姿态 提交于 2020-07-21 02:39:08
问题 I'm trying to validate a POST request using Laravel's FormRequest . The customer is submitting an order, which has an array of items. We are requiring the user to indicate whether the item needs special_delivery only if the asking_price > 500 and the quantity > 10 . The following are my intended rules: public function rules() { 'customer_id' => 'required|integer|exists:customers,id', 'items' => 'required|array', 'items.*.name' => 'required|string', 'items.*.asking_price' => 'required|numeric'

How to validate time in laravel

不问归期 提交于 2020-06-24 10:59:04
问题 I want to validate time in Laravel. Ex:- I want that when user input the time between 8 PM to 10 PM then it will show the validation error. How can I achieve that in Laravel 回答1: Use date_format rule validation date_format:H:i From docs date_format:format The field under validation must match the format defined according to the date_parse_from_format PHP function. 回答2: Probably this code would work in your controller. However it won't validate times from different days (eg 9pm - 3am next day)