0
我使用laravel-spark處理我的網站上的條形支付,用戶可以在其訂閱上應用優惠券,以便他們享有折扣,現在我想向用戶展示折扣在個人資料頁面上。
我搜索了關於如何檢索當前折扣的火花文檔,他們沒有在任何地方提及。
我發現laravel火花有電流()
CouponController此功能在CouponController方法來實現:獲得laravel-spark中給定用戶的當前折扣
/**
* 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);
}
我試圖調用此方法在我與Vue的觀點如下:
axios.get('/coupon/user/'+ this.user.id).then(response => {
console.log("response : ", response);
coupon = response.data.data;
if (coupon) {
//do something
}
}, error => {
console.log("some error occurred", error);
});
但是,即使用戶在他的條帶帳戶上有有效的優惠券,其響應始終爲空,並顯示204狀態碼。 有什麼建議?!