I
I
igor11122019-01-19 02:29:41
Laravel
igor1112, 2019-01-19 02:29:41

Laravel response SPA?

Hello. Let's say on the backend I have the following code:

if(...) {
        return response()->json([
            'message' => 'Some message!';
        ], 401);
} else {
        return response()->json([
            'message' => 'Other some message!'
        ], 401);
}

On the frontend, having received one of the answers, I need to implement different logic. But the response code is the same. this often happens. How to do it right? Should I check message in if? Didn't see them doing that.
And the second question is this 'message' in json, which is used everywhere, is it needed for debugging purposes, or can it be output to the user in flash messages?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vism, 2019-01-19
@igor1112

Evil uncles do not allow you to send other variables, except for message?

A
Artem, 2019-02-08
@ulkoart

return response()->json([
            'message' => 'Some message!';
            'code' => 1;
        ], 401);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question