Answer the question
In order to leave comments, you need to log in
How to get error messages and data from a post after a redirect?
All good. Tell me how to get error messages in the view after redirect
Here is an example
public function registrationTokenSave( Request $request , $token ){
$oEntryUser = $this->checkToken( $token );
$validator = Validator::make( $request->all() , $this->rules );
if ( $validator->fails() ){
return redirect()->back()
->withInput()
->withErrors($validator->errors());
}
return view('test');
}
->withInput()
->withErrors($validator->errors());
Answer the question
In order to leave comments, you need to log in
At the beginning of the file we write:
And the message can be displayed like this:
public function registrationTokenSave( Request $request , $token ){
$oEntryUser = $this->checkToken( $token );
$validator = Validator::make( $request->all() , $this->rules );
if ( $validator->fails() ){
Session::flash('errors', $validator->errors()); // Разовый показ сообщения.
return redirect()->back()
->withInput()
->withErrors($validator->errors());
}
return view('test');
}
@if (session('errors'))
@foreach(session('errors') as $err)
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>{{ $err }}</strong>
</div>
@endforeach
@endif
@if (count($errors) > 0)
@foreach($errors->all() as $error)
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>{{ $error }}</strong>
</div>
@endforeach
@endif
Hey! I hope the question is still relevant.
I'm using a basic error output construct:
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Имя:</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
{!! Form::text('name', null, array('class' => 'form-control input-sm')) !!}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question