Laravel Vouchers is a package by Marcel Pociot that allows users to redeem vouchers that are bound to models:
This package can associate vouchers with your Eloquent models. This might come in handy, if you need to associate voucher codes with content that is stored in your Eloquent models.
Here’s a basic example of how to create them and redeem them from the readme:
1$videoCourse = VideoCourse::find(1);2$voucher = $videoCourse->createVoucher();34auth()->user()->redeemVoucher($voucher);
You can also create vouchers with the
1$videoCourse = VideoCourse::find(1);23// Create 5 vouchers associated to the videoCourse model.4$vouchers = Vouchers::create($videoCourse, 5);
If you need to provide additional information for your voucher, you can pass an array of key/value data:
1$videoCourse = VideoCourse::find(1);23$vouchers = $videoCourse->createVouchers(2, [4 'from' => 'Marcel',5 'message' => 'This one is for you. I hope you like it'6]);78$voucher = $user->redeem('ABC-DEF');9$from = $voucher->data->get('from');10$message = $voucher->data->get('message');
You redeem a voucher with the
1$voucher = $user->redeemCode('ABCD-EFGH');23// Redeem a Voucher model instance4$user->redeemVoucher($voucher);
To learn more about this package, check out beyondcode/laravel-vouchers on GitHub.