$couponCode = $request->couponCode;
// Get coupon details by coupon code
$coupon = Coupon::where('couponCode', $couponCode)
->get()
->first();
$couponDetails = response()->json($coupon);
return $couponDetails->couponName;
That returns as:
Undefined property: IlluminateHttpJsonResponse::$couponName (500 Internal Server Error)
I am tring to get couponName value from couponDetails
2
Answers
The error you’re getting is because property you’re trying to access doesn’t exist for the class
IlluminateHttpJsonResponse
.You have two ways to avoid this:
Either return:
Get the data from JsonResponse class:
As another user already stated but not with more code, I will show you how to do it: