- How do I install and set up beyondcode/laravel-vouchers in a Laravel application?
- Install it with composer require beyondcode/laravel-vouchers, then publish the package migration and run php artisan migrate. Add the HasVouchers trait to any Eloquent model that should be able to issue vouchers. There are no external services, queues, or configuration files required, so a working demo typically takes under half a day. Reaching production quality takes longer because tests, authorization, and an admin surface are yours to build.
- How do I create and redeem a voucher with laravel-vouchers?
- You create a voucher through an issuing model that uses the HasVouchers trait, which stores a record in the vouchers table, and then call redeem() on the voucher to perform the state transition. Redemption sets the redeemed state and is the package's core behavior. Anything beyond that, such as generating the code string, retrying on collisions, or applying the business effect of the voucher, is application code you write.
- Can a voucher be bound to a specific model or user?
- Yes. Vouchers attach to any Eloquent model through a polymorphic relation, so a single vouchers table can serve promo codes, referral invites, license keys, and beta access without per-feature schema work. Because polymorphic owner columns normally carry no foreign key, deleting an owning model will orphan its vouchers. Define an archival and deletion policy yourself, since audit and re-issuance edge cases depend on it.
- How do I set expiry dates and usage limits on vouchers?
- The package supports expiry dates and usage limits as part of the voucher record, alongside custom redemption rules. The important caveat is that enforcement at your application boundary is your responsibility, so validate expiry and remaining uses before calling redeem() rather than assuming the package blocks it for you. Put those checks in a single service or action class so every entry point, including API endpoints, behaves the same way.
- Is laravel-vouchers safe for concurrent redemptions in production?
- Treat this as the load-bearing question and verify it in the package source rather than assuming. If redeem() is a read-then-write on the redeemed timestamp, two concurrent requests can both succeed against a single-use code, which is exactly what happens during flash sales and partner distributions. If the guarantee is absent, wrap redemption in a database transaction with lockForUpdate() or use a conditional update backed by a unique index, and budget that as real work. Add idempotency keys to redemption endpoints so retries cannot double-spend a voucher.
- Which Laravel and PHP versions does beyondcode/laravel-vouchers support?
- Check the illuminate/* and php constraints in the package's composer.json on Packagist rather than relying on the README, since constraints change between releases. Because you publish the migration, the schema becomes yours and upstream migration changes turn into manual merge conflicts across Laravel majors. Pin the version in composer.json and re-test redemption behavior after each Laravel upgrade.
- How do I store custom data such as plan, SKU, or discount amount on a voucher?
- The JSON data column is the package's only extension point, so business meaning like value, plan, SKU, currency, or campaign lives there. That is flexible but comes with no schema-level guarantees, no indexing, and no validation, so malformed payloads are possible. Validate the payload shape at the boundary where you create and read vouchers, and cast it to a typed value object in your application code.
- What are the limitations of laravel-vouchers compared to a full promotions engine?
- It is a single-purpose Eloquent primitive, not a promotions, entitlement, or ledger system. Discount math, stacking, exclusions, currency and tax handling, partial balances, and per-customer caps are all outside its model and must be built by you. State this explicitly to stakeholders early, or 'we added vouchers' will be heard as 'we shipped a promotions platform.'
- How do I control who can issue and redeem vouchers in Laravel?
- The package ships no authorization layer, so define policies or gates that distinguish issuing from redeeming and apply them in your controllers and form requests. Redemption sits on a critical path involving money and access, so also record an audit trail of who redeemed what and when. Keep the redemption endpoint idempotent and log failures, since flash sales and partner distributions are where these gaps surface.
- Is beyondcode/laravel-vouchers actively maintained and what are the alternatives?
- Beyond Code is a small commercial vendor with a broad portfolio, and a recent release suggests the package is alive, but release cadence, backlog responsiveness, and a security disclosure path should be confirmed rather than inferred. With roughly 700 stars and zero registry dependents, you will be early on the edge cases with little community corpus of failure modes, so be prepared to become the de facto maintainer. The upside is a small code footprint, which makes reversing the decision cost days rather than quarters; alternatives include a hand-rolled vouchers table or a dedicated promotions platform if you need discount logic.