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

imhuync's avatar

[SOLVED] Laravel API Routes 404 Not Found

Hi

I just started doing RESTful API with Laravel 9 but I am having a little problem with Form Request Validation.

Endpoint: POST /api/login

App\Http\Request\UsersRequest - Form Request Validation

public function authorize()
{
        return true;
}

public function rules()
{
        return [
            "username" => "required|string",
            "password" => "required|string"
        ];
}

App\Http\Controllers\UsersController - Controller

use App\Http\Requests\UsersRequest;

public function store(UsersRequest $request)
{
        dd($request->all());
}

When I send a JSON body like below (For validation check) I get back 404 Not Found page.

{
        "username": ""
}

When I send a JSON body like below everything is normal.

{
        "username": "imhuync"
}

Please help me. Thanks very much.

0 likes
6 replies
tisuchi's avatar

@imhuync Can you try with return true?

public function authorize()
{
        return true;
}
iftekhs's avatar

Can you try validating it without the UsersRequest and try validating using the Request $request and just check if it works or not.

mehrdad70's avatar

Did you call url like this in Postman? 127.0.0.1:8000/api/users

Snapey's avatar
Snapey
Best Answer
Level 122

make sure you are sending Accept: application/json header so that laravel knows to return a json response

at the moment validation error is causing it to try to redirect to the same url using a get request which you don't have, so a 404 is returned

4 likes

Please or to participate in this conversation.