Skip to content
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

New withGlobalErrors macro #1

Closed
bilfeldt opened this issue Nov 11, 2021 · 2 comments · Fixed by #2
Closed

New withGlobalErrors macro #1

bilfeldt opened this issue Nov 11, 2021 · 2 comments · Fixed by #2
Assignees

Comments

@bilfeldt
Copy link
Owner

bilfeldt commented Nov 11, 2021

There is an existing view method withErrors that is used like this:

view('post-index')
    ->withErrors(['field' => 'Some error'], 'default');

but the problem is that the errors are available as $errors only in the provided view, meaning two things:

  1. They override the global $errors used by validation and the method with same name withErrors() on redirects
  2. Any parent/child views do not have access to these errors (like for example the main layout)

I wrote a PR for this that was unfortunately rejected - see laravel/framework#39459

So this issue is about creating a macro withGlobalErrors that merges the errors to the global errors:

view('post-index')
    ->withGlobalErrors(['field' => 'Some error'], 'default'); // These messages are merged into the 'default' bag

This is how to merge: https://laravel.com/api/8.x/Illuminate/Support/MessageBag.html#method_merge

@bilfeldt bilfeldt changed the title New withGlobalError macro New withGlobalErrors macro Nov 11, 2021
@bilfeldt bilfeldt self-assigned this Nov 11, 2021
@bilfeldt
Copy link
Owner Author

PR rejected by Taylor and this is outside the scope of this package.

@bilfeldt
Copy link
Owner Author

Proper solution found in #2 where a new function addErrors was added which will add the errors to the global $errors instead of to a named local property with the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant