@imhuync Can you try with return true?
public function authorize()
{
return true;
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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.
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
Please or to participate in this conversation.