| Total Complexity | 4 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | trait HasCoupons |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Polymorphic relation to the coupons. |
||
| 18 | * |
||
| 19 | * @return MorphToMany |
||
| 20 | */ |
||
| 21 | 13 | public function coupons(): MorphToMany |
|
| 22 | { |
||
| 23 | 13 | return $this->morphToMany(app(CouponContract::class), Str::singular( |
|
|
|
|||
| 24 | 13 | config('couponables.pivot_table', 'couponables') |
|
| 25 | ))->withPivot( |
||
| 26 | 13 | call(CouponPivotContract::class)->getRedeemedAtColumn() |
|
| 27 | ); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Use the coupon. |
||
| 32 | * |
||
| 33 | * @param string $code |
||
| 34 | * |
||
| 35 | * @return CouponContract |
||
| 36 | */ |
||
| 37 | 15 | public function redeemCoupon(string $code): CouponContract |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Check if the coupon is already redeemed by the model at least once. |
||
| 49 | * |
||
| 50 | * @param string $code |
||
| 51 | * |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | 3 | public function isCouponRedeemed(string $code): bool |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Check if coupon with this code is already used. |
||
| 66 | * |
||
| 67 | * @param string $code |
||
| 68 | * |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | 3 | public function isCouponAlreadyUsed(string $code): bool |
|
| 76 |