rsodhia's avatar

Returning response from middleware

Is it possible to kill the script and simply return a JSON array from a middleware?

For example, having an auth middleware that, if the user is invalid or doesn't have the required permissions, just die there, with a standard JSON response. Right now, I have helper functions created to make sure I always send back the same response, but when I try to do

return [
    'success' => false,
    'error' => 'something'
];

in my middleware, I get a Array to string conversion error.

0 likes
1 reply
rsodhia's avatar

Of course, as soon as I post this, I tried doing it as a response object (response()->json([])) instead, and that worked.

Please or to participate in this conversation.