I have refereed these links but none of them are perfect and not working in my case. 1st , 2nd , 3rd and 4th
I have simple form when user submit it's go to controller and check all validation rules if has any error redirect back to last page and show error on view page .
register_form.blade.php
@if ($errors->has())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br>
@endforeach
</div>
@endif
<form class="form" method="post" action="{{url('/profile')}}" id="detail_validate" name="detail_validate ">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<div class="col-md-6 col-sm-6">
<div class="form-group floating-label">
<input type="text" class="form-control" id="f_name" name="first_name">
<label for="f_name">First Name<span class="form-required-field">*</span></label>
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group floating-label">
<input type="text" class="form-control" id="last_name" name="last_name" required>
<label for="middle_name">Last Name<span class="form-required-field">*</span></label>
</div>
</div>
</form>
register.php (controller)
public function register(Request $request) {
$rules = array(
'first_name' => 'required|alpha',
'last_name' => 'required|alpha'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
return Redirect::to('/matrimonial_profile')
->withErrors($validator);
} else {
dd('all good bro.....');
}
}
I have also check in official document official doc and I am going with right flow then when I'm getting error I don't know.
Error is below
Error says that : in FileLoader.php line 109: Array to string conversion
1). in FileLoader.php line 109
2). at HandleExceptions->handleError('8', 'Array to string conversion', '/var/www/metrimony/vendor/laravel/framework/src/Illuminate/Translation/FileLoader.php', '109', array('path' => '/var/www/metrimony/resources/lang', 'locale' => array('en' => 'English', 'hi' => 'Hindi'), 'group' => 'validation')) in FileLoader.php line 109
3). at FileLoader->loadPath('/var/www/metrimony/resources/lang', array('en' => 'English', 'hi' => 'Hindi'), 'validation') in FileLoader.php line 54
4). at FileLoader->load(array('en' => 'English', 'hi' => 'Hindi'), 'validation', '*') in Translator.php line 272
5). at Translator->load('*', 'validation', array('en' => 'English', 'hi' => 'Hindi')) in Translator.php line 110
6). at Translator->get('validation.custom.first_name.required', array(), array('en' => 'English', 'hi' => 'Hindi')) in Translator.php line 237
7). at Translator->trans('validation.custom.first_name.required') in Validator.php line 2109
8). at Validator->getCustomMessageFromTranslator('validation.custom.first_name.required') in Validator.php line 2045
9).at Validator->getMessage('first_name', 'Required') in Validator.php line 703
10). at Validator->addError('first_name', 'Required', array()) in Validator.php line 688
I don't know what is the connection between validation and language but my error says there is somthing wrong with language and validation in FileLoader.php file.