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

Adam_Commit's avatar

Call to third party API AFTER successful form submission - using form data

Hi everyone,

A question more around best approaches here. Within my application with a form (obviously), that is integrated with Google Maps (places for autocomplete) this is a vue js implementation which pings Google APIs to grab the correct data and then subsequently send this data with other form data to the controller to save etc.

However I am wishing to add another API integration which I am happy (and would prefer) to be done behind the scenes as don't want to confuse the user on the front end, but it's a highly valuable data set from an application point of view.

So in simple terms, I am wanting to call a 3rd party API after a successful (validated form submission as I will pass some data from the form to the API). My question is, where is the best place to call/store this 3rd call API integration. It is relatively simple, its a simple endpoint that accepts 1 parameter and returns a simple json object.

Should this integration be bundled in the controller (seems a little bit restrictive and will complicate the controller code), it shoudln't (isn't a model) as it doesn't have any relations - the return data will simply populate some additional DB fields.

How would anyone go about abstracting this service. Any pointers would be well received and greatly appreciated :)

Note this is a pure PHP API integration - no Laravel wrappers etc. For anyone interested - the API is What3Words :)

Cheers

Adam

0 likes
3 replies
Ap3twe's avatar
Ap3twe
Best Answer
Level 5

Create a Method in the same controller and reference it in the form controller like $this->apiController()

public function apiController(){

everything here

}

Adam_Commit's avatar

Ahhh right, so just like you as you may abstract validation from the store method to a separate method. Similarly just do the same the the API call...make sense. 👍

Ap3twe's avatar

Yes, Something like that. if it works Accept the answer thanks

Please or to participate in this conversation.