Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AlexNsk's avatar

Error messages output in API

Hi, everyone. When I try to logn in in my API, if all login data was provided correctly - everything is fine, but if I make some mistake I want to get messages with validation errors. But it`s just redirects me to homepage. Here is my Request:

class SignInRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'email' => 'required|exists:users',
            'password' => 'required|min:6',
        ];
    }
}

And Controller:

public function signIn(SignInRequest $request): JsonResponse
    {
        $authResult = Auth::attempt([
            'email' => $request->email,
            'password' => $request->password,
        ]);

        if($authResult) {
            Auth::user()->api_token = str_random(64);
            return response()->json([
                'name' => Auth::user()->name,
                'email' =>Auth::user()->email,
                'api_token' => Auth::user()->api_token
            ], 200);
        }
        return response()->json('user not found', 404);
    }
0 likes
1 reply
construct's avatar

Just curious but, How do you have the route setup? What are you getting in the network tab in the developer console (Make sure you have persist log checked for this)?

Please or to participate in this conversation.