Problem showing error messages on validation using Laravel 5.8 - php

Why won't error message display with the code below?
I can see the error message in page source code though.
#if($errors->has('slug'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('slug')}}</strong>
</span>
#endif
However this works:
#if($errors->has('slug'))
<p>{{ $errors->first('slug')}}</p>
#endif

The class "invalid-feedback" has display none in bootstrap 4.
You can add the class "d-block" to display it "invalid-feedback d-block"

Related

Laravel does not display my errors correctly

I've a little problem with Laravel, i'm displaying my errors like that :
{!! $errors->first('email', '<small class="help-block">:message</small>') !!}
But the error I get is : validation.unique
Do you know the reason ? Is it because i must to write all errors by myself ?
Thanks by advance ;)
I think if you need just error message then you do not need to pass additional field. :message
You can do it by just passing column name.
{{ $errors->first('email') }}
Laravel validation
Try this one
#if($errors->has('email'))
{{ $errors->first('email') }}
#endif

Why Laravel blade #error doesnt show the error?

I was testing this new Laravel fortify with Laravel 8 and got into an odd issue that I've never seen before.
for the input field validation of the registration form and login form, the blade error message that I made doesn't show if I don't use #error('[field name]') is-invalid #enderror to add the is-invalid class to the input field.
any idea why is that?
this is how I'm showing the error:
#error('[field name]')
<span class="invalid-feedback is-invalid" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
Here id the demo code I made:
https://gitlab.com/sxshateri/laravel-fortify

Laravel 7: Validation error message is not showing using key

I want to show validation errors right next to the field.
Therefore I am using this the #error directive.
#error('service_date')
<div class="error">{{ $message }}</div>
#enderror
But the error only shows up when iterating over all of them.
#if($errors->any())
{{ implode('', $errors->all('<div>:key - :message</div>')) }}
#endif
Using the above method, I can see that the key is correct. The output will be as follows:
service_date - The service date is not a valid date.
Other errors in the same form get displayed correctly. Why is behaving like this and how can I fix it?

Trying to get property of non-object error but works when page is refreshed

I get the error in the title sometimes but when I refresh a few times, my application works again.
Laravel.log shows this:
[2016-12-19 13:17:22] local.ERROR: exception 'ErrorException' with
message 'Trying to get property of non-object' in
storage\framework\views\e81b4a67320194ba9a4782ec91b02d51:12
storage/framework/views/e81b4a67320194ba9a4782ec91b02d51.php line 12:
<span class="block m-t-xs">
<strong class="font-bold"><?php echo e(Auth::user()->name); ?></strong> <!--line 12-->
</span>
do Auth::check() or Auth::user() before trying to access fields in user object. Its because that you are trying to get a property of the user object, but the user object is null. like this
<span class="block m-t-xs">
#if(Auth::check())
<strong class="font-bold">
{{ Auth::user()->name }}
</strong>
#endif
</span>
For some reason Auth::check() returned false but app didn't log me out. After clearing cookies and logging in again this error stopped happening.
I suspect the issue was that I changed the user and auth quite a bit but didn't clear cookies
You should check if the session has the authenticated user or not using auth()->check():
<span class="block m-t-xs">
<strong class="font-bold">
<?php echo (auth()->check()) ? e(Auth::user()->name) : ''; ?>
</strong>
</span>
You can use ternary operator to check if the user is authenticated or not.
Hope this helps!
Why you 're trying to use e()? try to dd(Auth::user()) then see the result or try
{{ Auth::user()->name }}

How can I add a success flash message for the password reset functionality of Laravel?

I'm using Laravel 5.1 and the built-in auth functionality. When testing it, however, I noticed there is no "Success" message when a user fills out the forgotten password form, the page simply refreshes, although the form does work.
How can I set a success variable for the forgotten password tool? I can't find the method that controls this anywhere.
Thanks
If you’re using Laravel’s built-in password reset functionality, then it does have a success message. You can see it here: https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Auth/ResetsPasswords.php#L95
You merely need to listen for it in your view and display it if it’s there:
#if (session('status'))
<p class="alert alert-success">{{ session('status') }}</p>
#endif
This will display the default message, which is:
Your password has been reset!
If you want to change this message, just change the relevant line in resources/lang/en/passwords.php.
Simply paste this function in your ResetPasswordController
protected function sendResetResponse(Request $request, $response)
{
return redirect($this->redirectPath())
->with('success', 'Password changed successfully.');
}
And to get the message in your blade view, use this code
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif

Categories