Category : laravel-validation

I need to apply a required rule to a array field in my form request when the another array field, in the same index, has a certain value. Example: public function rules(): array { return [ ‘data’ => ‘array’, ‘data.*.is_admin’ => ‘required|boolean’, ‘data.*.area’ => [ ‘nullable’, Rule::requiredIf($condition), // other rules… ] ] } When evaluating ..

Read more

In Laravel 8 app I defined boolean field $table->boolean(‘featured’)->default(false); and validation rules : ‘feature’ => ‘required|boolean’, But defining selection input on a form I have 1st “Select” item, like: <select class="form-control select2" id="featured" name="featured"> <option value="">Select…</option> @if($gigFeaturedList) @foreach($gigFeaturedList as $key=>$value) <option and I suppose that make my validation to work in invalid way, so when ..

Read more

I have a question about Laravel’s validation logic. My HTML code: <div class="row"> <div class="col-md-12"> <form id="carFilesForm" autocomplete="off" enctype="multipart/form-data"> <input name="car_files[]" type="file" multiple> <button type="submit">Upload</button> </form> </div> </div> I am submitting the form with ajax. My CSRF token is already specified in the global js file. (Additionally, I don’t have a problem with uploading files ..

Read more

I have an EmailAddress model that has an ’email_address’ property. This property must be unique, so I added a rule to my StoreEmailAddressRequest. The problem comes up when I want to update a model. In my UpdateEmailAdressRequest I added an entry: Rule::unique(’email_addresses’)->ignore($id); Now, when I try to update the model and don’t touch email_address, everything ..

Read more

I used Request to validate data public function rules () : array { return [‘order_type’ => ‘numeric|gt:0′]; } For example, my order_type=’abc’, I’ll be received 2 message in result order_type: [ ‘validate.numeric’, ‘validate.numeric.gt’ ] But I want only 1 message for both numeric validate and greater than 0 validate. And my result I want is: ..

Read more

I am trying to validate a form using form request like so. /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ ‘foo_required’ => [‘boolean’, ‘nullable’], ‘foo_id’ => [‘bail’, ‘required_if:foo_required,true’, new UniqueVendorId(request()->input(‘dest’), request()->input(‘cus_id’))], ]; } The above is my form request rules, where ..

Read more

I am trying to make a validation that will check whether at least one item is provided in an array following the steps in Custom Validation Rules Routes.php Route::middleware([‘auth:api’, ‘bindings’])->group(function () { Route::prefix(‘api’)->group(function () { Route::apiResources([ ‘exam-papers/{examPaper}/questions’ => ExamPaperQuestionsController::class ]); }); }); ValidateArrayElementRule.php namespace AppRules; use IlluminateContractsValidationRule; class ValidateArrayElementRule implements Rule { public function __construct() ..

Read more

{"message":"The given data was invalid.","errors":{"category_image":["The category image must be an image.","The category image must be a file of type: jpeg, png, jpg, gif, svg.","The category image may not be greater than 2048 characters."]}} this message shows every time even when I upload .jpg/.png/.jpeg file my validation code: $request->validate([ ‘category_name’ =>’required|min:3|max:20|unique:categories’, ‘publication_status’=>’required’, ‘category_image’ =>’required|image|mimes:jpeg,png,jpg,gif,svg|max:2048′, ]); my ..

Read more

I have a page with multiple forms on it but I need to validate a specific submitted form. In my view I have this for each input of the forms <div class="form-group"> <label for="name">{{ __(‘Name’)}}</label> <input class="form-control {{ $errors->has(‘name’) ? ‘is-invalid’ : ” }}" type="text" name="name" id="name" value="{{ old(‘name’, ”) }}"> @if($errors->storecomment->any()) <div class="invalid-feedback"> @foreach($errors->storecomment->all() ..

Read more

there I’m facing an issue with the validation, Input arrays should include at least one value for example when I submit a form I get the following inputs array:26 [ "_token" => "GMPKHos9nnC6zw6UGN4nFKVEGd5PoEpDe9lEPETw" "Customer" => "1" "Text_From_Date" => "07 Jun 2021" "From_Date" => "2021-06-07" "Text_Due_Date" => "16 Jun 2021" "Due_Date" => "2021-06-16" "Invoice_Id" => "INV-1" ..

Read more

I am trying to update the data and to do this I am using a method patch on my form. Update Validation Request use IlluminateValidationRule; ‘question’ => [ ‘required’, ‘string’, Rule::unique(‘faqs_questions’,’question’), ‘max:30’, ], If there are no changes in my question it gives me an error: The question has already been taken. dd($this->toArray()) on validation ..

Read more

I got this data from request: { "type": "custom", "start_week": "2020-W19" } And my validation rules are: return [ ‘type’ => ‘required|in:standard,custom’, ‘start_week’ => ‘required|date_format:Y-WW’, ]; Which gives me this result: "errors": { "start_week": [ "The start week does not match the format Y-WW." ] } I used this RegEx format before for validating week ..

Read more

I have problem to validate my image. Its ok on another project but in new project Laravel 8 always fail. View: <label class="btn btn-primary" for="img" style="margin-top: 25px">upload image</label> <input type="file" id="img" name="avatar" accept="image/*" hidden/> Controller: $validated = $request->validate([ ‘avatar’ => ‘image|mimes:jpeg,png,jpg,gif,svg|max:2048’, ]); Error: The avatar must be an image. The avatar must be a file ..

Read more

I am trying to test validation on a Laravel page public function user_can_create_event_page() { $user = User::factory()->create(); $event = Event::factory()->make()->toArray(); $response = $this->actingAs($user)->post(‘/events’, $event); $response->assertStatus(302); $this->assertNotNull(Event::where(‘name’, $event[‘name’])->first()); } public function user_receives_error_422_if_name_is_not_provided() { $user = User::factory()->create(); $event = Event::factory()->state([‘name’ => ”])->make()->toArray(); $response = $this->actingAs($user)->post(‘/events’, $event); $response->assertStatus(422); } and in my validation class EventStoreRequest extends FormRequest { ..

Read more

I want to change message from ValidYouTubeVideo (to translate it in Polish). $this->validateOnly($field, [ (…) ‘youtubeId’ => [‘unique:songs,youtubeId’, new ValidYoutubeVideo], ]); I saw something like that: ‘body.required’ => ‘A message is required’, but unfortunately I don’t know how can I use it. The best option will be __(), but this validation is in a vendor… ..

Read more

I have an array of inputs which I need to check for «distinct» statement. If validation fails I have to output error message like: «Property Size has duplicates». If I just put int index in message – it works alright: ‘propertyNames.*.distinct’ => ‘Parameter «’.$this->propertyNames[0].’» has duplicates’ But how to put some key variable in $this->propertyNames[] ..

Read more

I have Laravel/Vue application and I’m submiting form with file and some other data using axios. this.loading = true; this.errors = {}; let formData = new FormData(); formData.append(‘type’, this.type); formData.append(‘file’, this.file); formData.append(‘date’, this.date); axios.post(`/file-upload`, formData, { headers: { ‘Content-Type’: ‘multipart/form-data’ } }) .then((response) => { if (response.status === 200) { this.loading = false; // Success.. ..

Read more