I am using Laravel for a project and i am trying to validate some input fields from a form. I am using the Validator class.
Here is the code in my controller.
$validator = Validator::make($request->all(), [
'arithmos_kinhths' => 'required',
'kathgoria_kinhths' => ['required',Rule::notIn(['-'])],
'prohgoumenos_paroxos_kinhths' => ['required',Rule::notIn(['-'])],
'programma_kinhths' => ['required',Rule::notIn(['-'])],
'project_kinhths' => ['required',Rule::notIn(['-'])],
'kathogoria_epidothshs_kinhths' =>['required',Rule::notIn(['-'])],
'talk_to_eu_kinhths' => ['required',Rule::notIn(['-'])],
'pagio_kinhths' => 'required',
'sms_kinhths' => ['required',Rule::notIn(['-'])],
'internet_kinhths' => ['required',Rule::notIn(['-'])],
'international_kinhths' => ['required',Rule::notIn(['-'])],
'twin_sim_kinhths' => ['required',Rule::notIn(['-'])],
'wind_unlimited_kinhths' => ['required',Rule::notIn(['-'])],
]);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput();
}
In the blade file i am trying to catch the errors using the code bellow.
@if($errors->any())
@foreach($errors->all() as $error)
<script>
$.notify(
{
title: '<strong>ERROR!</strong>',
message: '{{$error}}',
},
{
type: 'danger',
},
)
</script>
@endforeach
@endif
Also i want to put the old values into the input fields using {{old('value'}}
The problem i have is that i can't combine both errors and inputs. If i return only the errors using withErrors($validator) the errors are printed out. And if i return only withInput i have the post values.
Any ideas?