@@ -11,10 +11,13 @@ class Vouchers
1111{
1212 /** @var VoucherGenerator */
1313 private $ generator ;
14+ /** @var \BeyondCode\Vouchers\Models\Voucher */
15+ private $ voucherModel ;
1416
1517 public function __construct (VoucherGenerator $ generator )
1618 {
1719 $ this ->generator = $ generator ;
20+ $ this ->voucherModel = app (config ('vouchers.model ' , Voucher::class));
1821 }
1922
2023 /**
@@ -47,7 +50,7 @@ public function create(Model $model, int $amount = 1, array $data = [], $expires
4750 $ vouchers = [];
4851
4952 foreach ($ this ->generate ($ amount ) as $ voucherCode ) {
50- $ vouchers [] = Voucher:: create ([
53+ $ vouchers [] = $ this -> voucherModel -> create ([
5154 'model_id ' => $ model ->getKey (),
5255 'model_type ' => $ model ->getMorphClass (),
5356 'code ' => $ voucherCode ,
@@ -67,7 +70,7 @@ public function create(Model $model, int $amount = 1, array $data = [], $expires
6770 */
6871 public function check (string $ code )
6972 {
70- $ voucher = Voucher:: whereCode ($ code )->first ();
73+ $ voucher = $ this -> voucherModel -> whereCode ($ code )->first ();
7174
7275 if (is_null ($ voucher )) {
7376 throw VoucherIsInvalid::withCode ($ code );
@@ -86,7 +89,7 @@ protected function getUniqueVoucher(): string
8689 {
8790 $ voucher = $ this ->generator ->generateUnique ();
8891
89- while (Voucher:: whereCode ($ voucher )->count () > 0 ) {
92+ while ($ this -> voucherModel -> whereCode ($ voucher )->count () > 0 ) {
9093 $ voucher = $ this ->generator ->generateUnique ();
9194 }
9295
0 commit comments