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

addykar06's avatar

Laravel API form submit error

I made an api of a form, when i submit the form the page expires. I know it is due to CSRF Token but i have passed csrf token in meta tag as well as inside the form @csrf. Can anybody help me with this error

0 likes
8 replies
Sinnbeck's avatar

Code? When you say api, does that mean that you are using Javascript?

Sinnbeck's avatar

@addykar06 So it is not actually an API but just a regular form on a blade page that submits to a controller?

addykar06's avatar

@Sinnbeck yup actually i am using a form on my website and the same form will be used for mobile app so i am send the form there, the form is also getting displayed in app but the form is submitting data its expiring

addykar06's avatar

@Sinnbeck routes/api.php CODE Route::get('/delegates/{headingcheck?}', [ApiController::class, 'delegates']);

this thing is working fine, displaying the form but its expiring on submit

@csrf //SOME INPUT FIELDS

This is my form code in the blade

Sinnbeck's avatar

@addykar06 How are you submitting to it? And why does it have csrf if its an api route? API's are normally stateless?

Please or to participate in this conversation.