Category : laravel-validation

{"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

table ‘angkatan’ I have table named ‘angkatan’ which has id, id_angkatan, nama_angkatan, and status. status column is enum contain ‘aktif’ and ‘tidak aktif’. i want to give rules for this table in laravel with validaition where this table only allowed to have maximum 4 and minimum 1 of status ‘aktif’. no rules for how many ..

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

I have already asked question about Laravel 5.7 validation, however it still does not work quite right. the validation is not executed at all when sending the content. public function update(Request $request, Player $player) { if(Auth::check()){ $playerUpdate = Player::where(‘id’, $player->id) ->update([ ‘first_name’ => $request->input(‘fist_name’), ‘last_name’ => $request->input(‘last_name’) ]); if($playerUpdate){ return redirect()->route(‘players.show’, [‘player’=> $player->id]) ->with(‘success’ , ..

Read more

My function works by itself but the validation is not executed. Does anyone know what I forgot to add? This is a snippet of my code: namespace AppHttpControllers; use AppPlayer; use AppTournament; use IlluminateHttpRequest; use IlluminateSupportFacadesDB; use IlluminateSupportFacadesAuth; public function store(Request $request) { $request->validate([ ‘first_name’ => ‘alpha|min:2|max:30’, ]); if(Auth::check()){ $foo = Foo::create([ ‘first_name’ => $request->input(‘fist_name’), ..

Read more

I have validation in Laravel application, but I can’t seem to make it work. I am making validation on Supplier model not request. public function requestOpening(Supplier $supplier) { $validator = Validator::make($supplier->toArray(), $this->fullValidationRules()); if ($validator->fails()) { return redirect("open-new/supplier/{$supplier->id}") ->withErrors($validator); } // … } I want hfm_code to be required only when is_hfm == 1. I tried ..

Read more

I am trying to apply the suggestions provided in this question How to validate array in Laravel? So my validation is ‘topics’ => ‘required|array’ Topics are required This works well especially if topics is an array greater than 1 unfortunately is I pass [] an empty array the validation fails How can I validate that ..

Read more

I’m trying to upload .docx file: enter image description here My validation rules: return [ ‘first_name’ => [‘required’, ‘latin_nameable’, ‘min:2’, ‘max:20’], ‘last_name’ => [‘required’, ‘latin_nameable’, ‘min:2’, ‘max:20′], ’email’ => [‘required’, ’email’], ‘location’ => [‘required’, Rule::exists(‘city’, ‘city_id’)->where(static function (Builder $query) { $query->where(‘vacancy’, 1); })], ‘skype’ => [‘required_without_all:phone’, ‘min:2’, ‘regex:/^[0-9A-Za-z.-_:]+$/’], ‘phone’ => [‘required_without_all:skype’, ‘phone:AUTO’], ‘cv’ => ‘mimes:docx,doc’, ..

Read more