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

TimeSocks's avatar

Getting response from a POST request

Hi folks,

Let's say I use Vue and Axios to post data to a Laravel controller to, say, create a booking in a database. As part of the creation process, a booking reference is generated. I can return this reference as a signal to Vue that the POST request was successful. How can I grab this response to display the reference to the customer?

0 likes
6 replies
walidabou's avatar

Can you clarify your question more? Do you want to return the newly created booking to the customer ?

TimeSocks's avatar

Well, I don't need to return the whole booking, just the reference would be fine, so I could display a thank you message, here's your reference number etc.

walidabou's avatar

So you can return just the reference:

return response()->json(['reference' => $booking->reference]);
TimeSocks's avatar

Yes. Returning the reference isn't the problem. It's getting it into my Vue instance I don't know how to do, given that it's a response to a POST request and not the results of a GET.

walidabou's avatar

Do you mean that you don't know how to handle the response in your frontend ?

TimeSocks's avatar

Yes, I guess I am. How do I access the response with Vue and, say, assign it to a variable?

EDIT: I can just make the request equal a variable. I am an idiot.

Please or to participate in this conversation.