-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding $errors variable in case of HTTP exceptions #23133
Comments
I somehow find your usage of In general, you should always check for existence of variables before using them (especially if they are some sort of optional like here). Meaning |
Actually, in a route like /home with no errors in the session, $errors is set to a empty view error bag through \Illuminate\View\Middleware\ShareErrorsFromSession. I agree that in general, we should always check for existence of variables before using them and I saw that we have in the framework a convenient way to avoid these checks for the $errors variable. So, the PR I suggested is just an extension of this feature to the HTTP exceptions use case. Hope this clarifies |
Btw, here are some comments from : \Illuminate\View\Middleware\ShareErrorsFromSession
|
PR commit has been merged : #23139 |
Description:
Hello everyone, hope you are doing well.
Let's say you have a custom HTTP error view in resources/views/errors, let's call it 404.blade.php.
In this view, you extend a general master view including the HTML skeleton used all over the web app.
In your general master view, you also have your navbar with a login form using the $errors variable. e.g.: using it in this way: $errors->has('password')
Let's say a user enters a non valid URL and gets redirected to 404.blade.php
There is an exception stating that $errors is undefined. Indeed, $errors is used as part of 404.blade.php and should be empty.
A fix to this issue might be to bind $errors to an empty ViewErrorBag in case of HTTP exceptions. This might be done like in the \Illuminate\View\Middleware\ShareErrorsFromSession
What do you think ?
Here is the related PR: #23139
Steps To Reproduce:
The text was updated successfully, but these errors were encountered: