In Laravel 5.1 Project
I'm getting this Ajax Response As Error
{
"success":false,
"errors":{
"drugs_power":["The drugs power field is required."]
}
}
i need a error validation like this image i can make it by laravel validator by this code(return From Controller),
$this->validate($request, [
'drugs_name' => 'required|unique:drugs',
'drugs_group_name' => 'required',
'drugs_power' => 'required'
]);
Show In blade.php by this code
<div class="form-group{{ $errors->has('drugs_power') ? ' has-error' : '' }}">
<label for="userName">Power</label>
<div>
<input type="text" class="form-control" name="drugs_power"
value="{{old('drugs_power')}}">
@if ($errors->has('drugs_power'))
<span class="help-block">
<strong>{{ $errors->first('drugs_power') }}</strong>
</span>
@endif
</div>
</div>
How can i make ajax+laravel validation just like that??
Passing in a 3rd parameter to validate
allows you to specify a custom message, as seen here. You can use "dot" notation to specify the error message to a specific field.
$this->validate($request, [
'drugs_name' => 'required|unique:drugs',
'drugs_group_name' => 'required',
'drugs_power' => 'required'
], [
'drugs_power.required' => 'Your custom message here.'
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With