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
Related
I have a problem with showing error messages or session messages in laravel.
Comment the bootstrap cdn, but makes no differences.
have code like this, works correctly, refreshing the view, but not displaying errors:
Controller.php
return redirect()->route('trainers.show',[$trainer])->with('status','Entrenador actualizado correctamente');
blade.php
#if (session('status'))
<div class="alert alert-success">
{{session('status')}}
</div>
#endif
Controller.php
$validatedData = $request->validate([
'name' => 'required|max: 10',
'avatar' => 'required|image',
'slug' => 'required',
'description' => 'required',
]);
blade.php
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $message)
<li>{{ $message }}</li>
#endforeach
</ul>
</div>
#endif
Regarding the session status, you can use \Session::has('status') and \Session::get('status'), like so:
#if(\Session::has('status'))
<div class="alert alert-success">
{{ \Session::get('status') }}
</div>
#endif
And on your errors, you can also use has(), like so:
#if ($errors->has())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error}}</li>
#endforeach
</ul>
</div>
#endif
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.
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'
When user tried to go user dashboard without login, it return to login page. it works perfectly. but I need to show message on login page using middleware that 'please login to see this page.'
I tried {!! $errors->first('loginpermission', ':message') !!}
But it not working
Please help me how to use this.
Add these codes in your login.blade page
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
#if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
#endif
Add below code in your middleware at condition when user is not logged in
return redirect('/login')->with('error', 'please login to your account');
#if ($errors->has('loginpermission'))
{{ $errors->first('loginpermission') }}
#endif
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