I have problem with Laravel as title say. My code:
Function in controller:
$validator = Validator::make($request->all(), [
'login' => 'required|max:10',
'katalog' => 'required',
'limitip' => 'required|ip',
]);
if($validator->fails()){
return redirect('something/toedit/someone')->withErrors($validator)->withInput();
}
else{
echo "Clear.";
}
And route:
Route::get('something/toedit/{login}',['middleware' => 'auth', 'uses'=>'MyController@editAccountGet']);
Route::post('something/toedit',['middleware' => 'auth', 'uses'=>'MyController@editAccountPost']);
And now problem is that this code in my view always return nothing.
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Also {{count($errors)}} it's equal 0. But if i use code like this:
@if (Session::has('errors'))
{{var_dump(Session::get('errors'))}}
@endif
It's returning in my view that:
object(Illuminate\Support\ViewErrorBag)#146 (1) { ["bags":protected]=> array(1) { ["default"]=> object(Illuminate\Support\MessageBag)#147 (2) { ["messages":protected]=> array(1) { ["login"]=> array(1) { [0]=> string(48) "The login may not be greater than 10 characters." } } ["format":protected]=> string(8) ":message" } } }
Can someone help me to access errors from $errors variable in my blade view? I'm really confused here.
->withFoo('bar')bar will be added as session flash in foo key. - Abhishek