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

devkon98's avatar

The POST method is not supported for this route. Supported methods: GET, HEAD. I am using the API.PHP

Hello i am making an API with laravel, everything works fine just now i added date filter to give results from date A to date B. So when i press submit i get this error:

The POST method is not supported for this route. Supported methods: GET, HEAD.

I searched online but all are for web.php file not for api.php this is my code until now:

<form method="POST" action="{{ url('api/outlay') }}"> @csrf @method('GET') <label for="startdate">Start Date</label> <input type="date" name="startdate" id="startdate"/> <label for="enddate">End Date</label> <input type="date" name="enddate" id="enddate"/> <input type="submit" value="Shfaq vlerat"> </form>

This is my api.php route:

Route::get('outlay/{startdate?}/{enddate?}',[GetValuesController::class,'getOutlays']);

0 likes
6 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Why is it in api.php when it isnt an api route? If you dont know what an API is we are happy to help you out :)

Anyways. You set the type of the route to get()

Route::post('outlay/{startdate?}/{enddate?}',[GetValuesController::class,'getOutlays']);

Or you can do

<form method="GET" action="{{ url('api/outlay') }}">
1 like
devkon98's avatar

@Sinnbeck the thing is that the url is used as api i saw on internet that for this i should make it in the api.php file

Sinnbeck's avatar

@devkon98 Yes api routes goes in the api.php. But once you use a route in a form, it is no longer an api, but a web form, and then the route goes in web.php. The returned data for api/web forms are quite different.

1 like
devkon98's avatar

@Sinnbeck I did this <form method="GET" action="{{ url('api/outlay') }}"> i do get my values but only as Json they show up

Sinnbeck's avatar

@devkon98 Yes. That is why I said to use a route in web.php. You dont use api routes in a regular webform

It might feel like you are duplicating routes, but that is most likely not the case. Often your web routes will return full pages with mixed data. An api route just returns a single resource type

1 like

Please or to participate in this conversation.