Skip to content

Handling Laravel failed jobs messages #449

Answered by ajnsn
lucaros97 asked this question in Help
Discussion options

You must be logged in to vote

@lucaros97 Afaik Laravel's RedirectResponse does not have a withError() method.

What you can do is to use the withErrors() method and choose a field for your error, e.g. for the login response:

return back()->withErrors(['email' => 'The email and password that you entered did not match our records.']);

But this is not too reusable.
Therefore I often add a property to Inertia's shared data, e.g. "message".

public function share(Request $request) : array
{
    return array_merge(parent::share($request), [
        'message' => $request->session()->get('message'),
    ]);
}

This can be populated by your exception handler like this:

return back()->with('message', 'Something went wrong');

In yo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lucaros97
Comment options

Answer selected by claudiodekker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants