The value of $couponDetails->couponName cannot be returned in Laravel
P粉714890053
2023-08-20 21:26:59
<p><br /></p>
<pre class="brush:php;toolbar:false;">$couponCode = $request->couponCode;
// Get coupon details through discount code
$coupon = Coupon::where('couponCode', $couponCode)
->get()
->first();
$couponDetails = response()->json($coupon);
return $couponDetails->couponName;
</pre>
<p>The return result is as follows:</p>
<blockquote>
<p>Undefined property: IlluminateHttpJsonResponse::$couponName (500 Internal Server Error)</p>
</blockquote>
<p>I am trying to get the value of couponName from couponDetails</p>
As another user already mentioned, but without more code I will show you how to do it:
The error you are getting is because the property you are trying to access does not exist in class
Illuminate\Http\JsonResponse
.You have two ways to avoid this problem:
Or return:
Get data from JsonResponse class: