I clicked on login, but the right side of register the errors shows up.
this is my view
<!-- REGISTER AREA LEFT SIDE -->
<div class="col-md-6">
<h3>Member Login</h3>
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form role="form" method="POST" action="{{ URL::route('login') }}">
....
</div>
<!-- REGISTER AREA RIGHT SIDE -->
<div class="col-md-6">
<h3>Member Registration</h3>
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form role="form" method="POST" action="{{ URL::route('register') }}">
....
</div>
and this is my controller return
return Redirect::back()
->withInput()
->withErrors($validation);
any way to rename the error with login_error and register_error? how to separate them into two variables, cause it conflict and shows both message on right side.
Your fields have names in html, and laravel binds the error to their names so that you can display the error for a specific field, so you can wrap the login form error block with something like:
#if($errors->first('login_email') || $errors->first('login_password'))
// ...
#endif
and the registration form error block with:
#if($errors->first('register_email') || $errors->first('register_password') || $errors->first('register_password_bis'))
// ...
#endif
This may not be the best solution, but I know it works and it will avoid to use hacks. Plus it does not add too much boilerplate as you do not have a lot of fields there.
Depending on how you built your constructor, you could also flash a message in the session in order to tell your view which form you validated:
Login
#if (count($errors) > 0 && Session::has('validated_login_form') == true)
// ...
#endif
Registration
#if (count($errors) > 0 && Session::has('validated_registration_form') == true)
// ...
#endif
Another way of doing it would be to look how the withErrors($validation) function works in Laravel sources and see if you can reproduce it yourself but naming $errors differently depending on the form you just validated.
Related
I'm trying to display error message for login credential
Response from API:
{#291 ▼
+"error": "invalid_credentials"
+"error_description": "The user credentials were incorrect."
+"message": "The user credentials were incorrect."
}
Blade HTML:
#if($errors->any())
<ul class="alert alert-danger form-group row">
#foreach ($errors->all() as $error)
<li >{{ $error }}</li>
#endforeach
</ul>
#endif
But i'm getting only error message invalid_credentials.
Now i want the message display on mine blade view.
Can anyone help me to get this done.
Thank you in advance.
You're only displaying the $error variable from your error. If you want to display only message, change your code to something like this:
#if($errors->any())
<ul class="alert alert-danger form-group row">
#foreach ($errors->all() as $error)
<li >{{ $error->message}}</li>
#endforeach
</ul>
#endif
Not tested, but should give you desired result.
When I used Laravel 5.8 I could get information about errors like this :
#if(count($errors > 0))
<ul class="error-list" >
#foreach($errors->all() as $error)
<li class="error-list-element">{{$error}}</li>
#endforeach
</ul>
#endif
It worked completly fine.
Since Laravel 6.0 was released the code above results in error :
Object of class Illuminate\Support\ViewErrorBag could not be converted to int
So how can I get information about errors in Laravel 6.0?
Here is code :
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
Hope this will help :)
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
here's my error
my controller
this is my code at blade file
#if(count($errors))
<div class="alert alert-danger">
<ul>
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
Follow this example
'name' => 'required|string|min:5|max:35'
I have two forms on a page (a blade template). Now I want to display form errors so I use:
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
Now I have errors on both forms:
You can use this for laravel validation error. it throw specific error in specific field. You have to use this in every input control.
#if ($errors->has('input_name'))<p class="text-danger">
{!!$errors->first('input_name')!!}</p>#endif
I am using with() helper to pass some error messages to views. My code for this is
redirect('somewhere')->with('message', 'show some message')
Then in the targeted view to catch the message I have this:
#if(count($errors)>0)
<div class="alert alert-success">
<ul >
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
But no message is delivered to the view. What's the problem here?
redirect('somewhere')->withErrors(['message', 'show some message'])
Please check this link Redirecting With Flashed Session Data
In targeted view you can handle message like this
#if (session('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
#endif