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

Deekshith's avatar

Laravel create a form and send form post to REST API.

i have created a form in laravel and now i want to pass the form data to REST API with ContentType: application/json. How to create a basic logic for this in controller?

0 likes
5 replies
tykus's avatar

What Controller are you meaning; do you own the REST API?

Deekshith's avatar

No i just want to send the form data to the API in ContentType: application/json format. I am planning like below

  1. create a form post route in my laravel application.
  2. add that route in form action and in controller i will pass form data to REST API.

For this i can use CURL?

CodeNathan's avatar

You could create a middleware and add the following :

 $request->headers->set('Content-Type', 'application/json');

Deekshith's avatar

I am planning like below

create a form post route in my laravel application. add that route in form action and in controller i will pass form data to REST API. For this i can use CURL?

Please or to participate in this conversation.