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

Mahmoud_Abd_Al_Karim's avatar

get the current discount for a given user in laravel-spark

I'm using laravel-spark to handle stripe payments on my website, the users can apply coupons on their subscriptions so they will have discounts, now I want to show user discount on the profile page. I searched on the spark documentation about how to retrieve the current discount and they didn't mention that anywhere. I found that laravel-spark has this feature implemented in the CouponController method current() CouponController :

    /**
 * Get the current discount for the given user.
 *
 * @param  Request  $request
 * @param  string  $userId
 * @return Response
 */
public function current(Request $request, $userId)
{
    $user = Spark::user()->where('id', $userId)->firstOrFail();

    if ($coupon = $this->coupons->forBillable($user)) {
        return response()->json($coupon->toArray());
    }

    abort(204);
}

I tried to call this method in my view with Vue as the following:

 axios.get('/coupon/user/'+ this.user.id).then(response => {
    console.log("response : ", response);
    coupon = response.data.data;
    if (coupon) {
        if (coupon.percent_off) {
            return coupon.percent_off + '%';
        } else {
            console.log(Vue.filter('currency')(coupon.amount_off / 100));
        }
    }
}, error => {
    console.log("some error occurred", error);
});

but the response is always empty with 204 status code, even if the user has a valid coupon on his stripe account. any suggestions ?!

0 likes
0 replies

Please or to participate in this conversation.