laravel-validation

How can I add a join to a custom exists rule for a laravel validator?

∥☆過路亽.° 提交于 2020-06-22 12:27:30
问题 The validator in laravel can have a customization of the exists database rule, for instance if you need to check an extra column. An example from the manual: use Illuminate\Validation\Rule; Validator::make($data, [ 'email' => [ 'required', Rule::exists('staff')->where(function ($query) { $query->where('account_id', 1); }), ], ]); The query in the closure is not typehinted, so i'm not quite positive what kind of object this is. I can see that the DatabaseRule itself only has some function

Failed validation returns default error message even though custom messages supplied

百般思念 提交于 2020-05-10 03:24:09
问题 I'm not getting the response I expect. This is the controller code for a Location web-service request: <?php namespace App\Http\Controllers; use App\Location; use Illuminate\Http\Request; class LocationController extends Controller { /** * Action method to add a location with the supplied Data * * @param \Illuminate\Http\Request $p_oRequest Request * * @return JSON */ public function add(Request $p_oRequest) { try { $p_oRequest->validate( array( 'name' => 'required|alpha_num', 'user_id' =>

How i can return a customized response in a FormRequest class in Laravel 5.5?

风格不统一 提交于 2020-03-18 04:00:30
问题 I am making an API and i want return the array of errors with a format as the one that $validator->errors(); generates when i validate the request by the manual way. But i cant manipulate the response. I wanna find thhe correct way to make it. This could be done in Laravel 5.4 with the formatErrors method and including the Illuminate\Contracts\Validation\Validator class in the FormRequest class but for version 5.5 it does not work. I do not know how to do it. This is my Controller: <?php

Laravel preg_match(): Unknown modifier ']'

给你一囗甜甜゛ 提交于 2020-02-23 03:58:24
问题 Im wokring on Laravel 4.2. Im trying to use validator to validate a name field with regex here is my rule below: public static $rules_save = [ 'name' => 'required|regex:/[XI0-9/]+/|unique:classes' ]; But as soon as I call the rule to be validated an error is thrown see below: preg_match(): Unknown modifier ']' In the following location: protected function validateRegex($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'regex'); return preg_match($parameters[0],

Laravel preg_match(): Unknown modifier ']'

一个人想着一个人 提交于 2020-02-23 03:56:10
问题 Im wokring on Laravel 4.2. Im trying to use validator to validate a name field with regex here is my rule below: public static $rules_save = [ 'name' => 'required|regex:/[XI0-9/]+/|unique:classes' ]; But as soon as I call the rule to be validated an error is thrown see below: preg_match(): Unknown modifier ']' In the following location: protected function validateRegex($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'regex'); return preg_match($parameters[0],

Validate array of inputs in form in Laravel 5.7

不想你离开。 提交于 2020-01-30 12:05:07
问题 My form has the same input field multiple times. My form field is as follows: <input type='text' name='items[]'> <input type='text' name='items[]'> <input type='text' name='items[]'> And request contains ($request['items'): array:1 [▼ "items" => array:3 [▼ 0 => "item one" 1 => "item two" 2 => "item three" ] ] I want atleast one of the items to be filled. My current validation in the controller is $validator = Validator::make($request->all(),[ 'items.*' => 'required|array|size:1' ]); It does

Laravel request validation with multiple forms on the same page

血红的双手。 提交于 2020-01-24 07:49:32
问题 I have three different forms on the same page. All inputs has it's own validation rules, code in Request file has structure like this: public function rules() { return [ // 'sold' => 'required', 'unit_in_stock' => 'required', 'unit_price_gbp' => 'required', 'returned_item' => 'required', ]; } public function messages() { return [ 'sold.required' => 'Please enter quantity of sold parts', 'unit_in_stock.required' => 'Please enter quantity of sold parts', 'unit_price_gbp.required' => 'Please

Laravel request validation with multiple forms on the same page

半腔热情 提交于 2020-01-24 07:49:09
问题 I have three different forms on the same page. All inputs has it's own validation rules, code in Request file has structure like this: public function rules() { return [ // 'sold' => 'required', 'unit_in_stock' => 'required', 'unit_price_gbp' => 'required', 'returned_item' => 'required', ]; } public function messages() { return [ 'sold.required' => 'Please enter quantity of sold parts', 'unit_in_stock.required' => 'Please enter quantity of sold parts', 'unit_price_gbp.required' => 'Please

Laravel 5 Request - altering data

半腔热情 提交于 2020-01-23 07:06:28
问题 I have come across an instance where I need to alter the data that needs to be validated i.e. when no slug has been submitted, create one from the title and then validate that it is unique. The request has a method replace() which is supposed to replace the input data on the request but it doesn't appear to work. Can anyone shine a light on this? This is what I have: <?php namespace Purposemedia\Pages\Http\Requests; use Dashboard\Http\Requests\Request; use Illuminate\Auth\Guard; class

how to pass custom validation message to cviebrock/image-validator in laravel?

喜你入骨 提交于 2020-01-15 05:01:00
问题 I am using cviebrock for validating image size in laravel. And thats working fine. But I want to customize the error message. I created an array of message $messages = array( 'image-size' => 'My custome message.', ); and passed to $validation = Validator::make(array($file => $fileObj), array($file => $rules), $messages); But thats not working. -Thanks Arun 回答1: You're using the wrong name, it should be with an underline, like $messages = array( 'image_size' => 'My custome message.', ); 来源: