Level 2
Your Code look fine. can you share your request from browser's dev tool network tab....
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using Vue on my client-side. On one of my controllers, I'm checking the condition and returning responses with error codes. The issue is I can't access the message in Vue that I'm passing from the controller. I'm getting the error code message.
Controller
public function store(BookingAddOnsFormRequest $request)
{
$booking = Booking::whereId($request->booking_id)
->whereUserId(auth('client')->user()->id)->first();
if (!$booking->canBookAdditional()) {
//here I'm passing the message with status code 400.
return response()->json(['message' => trans('book_additional.booking_closed')], 400);
}
$addOnBooked = BookingAddOn::create($request->getData());
return response()->json(['addon' => $addOnBooked, 'message' => trans('book_additional.add_on_added')], 201);
}
Vue
add() {
axios
.post("/laiylaty/add-on", {
// some action
})
.then(response => {
//some action
this.notificationAlert("success", response.data.message);
})
.catch(response => {
//some action
//here when I do console log I'm getting
//Error: Request failed with status code 400
//instead of the actual message that I'm passing from the action
this.notificationAlert("error", response.message);
});
},
Your Code look fine. can you share your request from browser's dev tool network tab....
Please or to participate in this conversation.