Issue
Laravel pops up the integer validation message when the input is null
View
<div class="form-group">
<label>Sipƫrfaqja(Metra Katror)</label>
<input type="number" name="area" value="{{old('area')}}"
class="form-control form-control-border @error('area') is-invalid @enderror "
placeholder="220">
@if($errors->has('area'))
<div style="color: red">{{ $errors->first('area') }}</div>
@endif
</div>
Controller
$rules = [
'area' => 'integer',
];
$messages = array(
'area.integer' => 'Area should be integer value',
);
I leave the input null, but this message appears in the frontend Area should be integer value.
Solution
as in Laravel doc:
By default, Laravel includes the TrimStrings and ConvertEmptyStringsToNull middleware in your application's global middleware stack. These middleware are listed in the stack by the App\Http\Kernel class. Because of this, you will often need to mark your "optional" request fields as nullable if you do not want the validator to consider null values as invalid.
so, your code should look like:
$messages = array(
'area.integer' => 'nullable|integer',
);
Answered By - OMR
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.