-
Hello, public function myFunction()
{
MyJob::dispatch();
return back();
} If my jobs fail I use the default failed Laravel method which allow me to take some actions. In this case I want to throw an Exception to show in the Vue component the error message: public function failed(Throwable $exception)
{
throw MyCustomException::jobFailed();
} And in my Exception I have this: public static function jobFailed()
{
return new static("Something went wrong! Check your data and try again");
} Now I jave added a specific response in my public function render($request, Throwable $exception)
{
if ($exception instanceof CannotAddRegistrar) {
return back()->withError('Something went wrong');
}
return parent::render($request, $exception);
} But nothing seems to be passed in the Inertia props in my Vue component. Any way to get this working? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@lucaros97 Afaik Laravel's What you can do is to use the return back()->withErrors(['email' => 'The email and password that you entered did not match our records.']); But this is not too reusable. 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 your frontend, you just need the |
Beta Was this translation helpful? Give feedback.
@lucaros97 Afaik Laravel's
RedirectResponse
does not have awithError()
method.What you can do is to use the
withErrors()
method and choose a field for your error, e.g. for the login response:But this is not too reusable.
Therefore I often add a property to Inertia's shared data, e.g. "message".
This can be populated by your exception handler like this:
In yo…