0
votes

I have a Request file to validate the form. What I am encountering is that, I have at least 24 form fields to validate, but the problem is fields get validated and return back to the view, when validation fails. But the errors is not get sent to view. But, I mentioned the rules for lets say only 6 fields, then the message is being displayed properly in the view.

I have done the research on stackoverflow, and tried every solutions, but none work for me.

1
post your code... - sta
I have a form request to validate, and I have used that in my controller to validate the fields, the validation is working fine, but the $errors variable contains empty data when return back to view on validation fails - sudip adhikari
how do you sure that the errors is not get sent to view ? - sta
@if($errors->any()) dd($errors); @endif this returns empty when the validation fails - sudip adhikari
Share your controller code - sta

1 Answers

0
votes

use this type of dorm fields in your view

 <div class="col-8 ml-auto">
 <input id="serialNumber" type="text" class="form-control t-cap"
 name="serialNumber" value="{{ $invoice->serialNumber }}">
 </div>
        
@if ($errors->has('serialNumber'))
<span class="col-md-12 form-error-message">
<small for="serialNumber">{{ $errors->first('serialNumber') }}</small>
</span>
@endif
</div>

And in Your Controller use Like This

$rules = array(
            'customer.mobile'=> 'required|regex:/\+91[[:space:]]\d{10}/',
            'serialNumber'  => 'required',
        );

        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails()) {

            return Response::json(array(
                'status' => 0,
                'errors' => $validator->errors()
            ), 400);

        }