beyondcode / laravel-vouchers Goto Github PK
View Code? Open in Web Editor NEWAllow users to redeem vouchers that are bound to models.
License: MIT License
Allow users to redeem vouchers that are bound to models.
License: MIT License
Please add support php 8
Hi there,
when can we expect support for laravel 6.0 as I am currently unable to upgrade
For first, thanks for the job, very interesting.
How about allowing model relation as optional (model defined as nullableMorphs in migration) for more flexibility? In this way, a voucher not related to a specific model / product could be created, for more generic purpose.
Model in function Vouchers create() could be a Nullable type:
public function create(?Model $model, int $amount = 1, array $data = [], $expires_at = null)
{
$vouchers = [];
foreach ($this->generate($amount) as $voucherCode) {
$vouchers[] = $this->voucherModel->create([
'model_id' => ($model instanceof Model) ? $model->getKey() : null,
'model_type' => ($model instanceof Model) ? $model->getMorphClass() : null,
'code' => $voucherCode,
'data' => $data,
'expires_at' => $expires_at,
]);
}
return $vouchers;
}
So we could call:
Vouchers::create(null, 1, [
'from' => 'Marcel',
'message' => 'This one is for you. I hope you like it',
'discount' => '1000€',
]);
Vouchers::create, $model::createVouchers and $model::createVoucher would continue to works as expected.
How we can create vouchers from the laravel nova panel?
In trait CanRedeemVouchers, function
/** * @return mixed */ public function vouchers() { return $this->belongsToMany(Voucher::class, config('vouchers.relation_table'))->withPivot('redeemed_at'); }
may add table param ``
Having followed the installation instructions here, I get the following when trying to publish the config file:
% php artisan vendor:publish --provider=BeyondCode\Vouchers\VouchersServiceProvider --tag="config"
INFO No publishable resources for tag [config].
Perhaps this command is incorrect?
Migration throws following error
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table user_voucher add constraint user_voucher_user_id_foreign foreign key (user_id) references users (id))
MySQL Version : mysql Ver 14.14 Distrib 5.7.25
When run this
php artisan vendor:publish --provider=BeyondCode\Vouchers\VouchersServiceProvider --tag="config"
this is what I get:
No publishable resources for tag [config].
Publishing complete.
With this I am unable to edit the config file for my User Model
I am using laravel 8 where we have the models inside the Models folder.
When we're at cart we always want to know first, what happen if i apply this voucher in the transaction. But the current development has no pre-apply condition. that make us always have to apply the voucher first to know the effect of the voucher.
I hope this issue could marked as enhancement or as feature add
For example:
A school class (30 students) can redeem a code for their class.
But you want to count on how many times the voucher has been redeemd.
After 30 redeems, the voucher is no longer valid.
Code example:
Schema::create('vouchers', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->integer('max_redeems')->default(30); // new
$table->integer('current_redeems')->default(0); // new
$table->timestamps();
});
class Voucher extends Model
{
protected $fillable = ['code', 'max_redeems', 'current_redeems'];
public function isValid()
{
return $this->current_redeems < $this->max_redeems;
}
public function redeem()
{
if ($this->isValid()) {
$this->current_redeems++;
$this->save();
return true;
}
return false;
}
}
Creating a "laravel/laravel" project at "./test-vouchers"
Installing laravel/laravel (v9.3.2)
Then
➜ test-vouchers git:(master) composer require beyondcode/laravel-vouchers
Using version ^2.0 for beyondcode/laravel-vouchers
./composer.json has been updated
Running composer update beyondcode/laravel-vouchers
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires beyondcode/laravel-vouchers ^2.0 -> satisfiable by beyondcode/laravel-vouchers[2.0.0].
- beyondcode/laravel-vouchers 2.0.0 requires illuminate/config ^8.0 -> found illuminate/config[v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require beyondcode/laravel-vouchers:*" to figure out if any version is installable, or "composer require beyondcode/laravel-vouchers:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
Thanks.
Hi,
I want custom coupon code to be store in place of random code is this possible.
Thanks
run php artisan vendor:publish --provider=BeyondCode\Vouchers\VouchersServiceProvider --tag="config" not generate vouchers config file
Config relation table is pivot_table in migration file but key in config is relation_table
I am using vuejs to check if a voucher code exists before adding it to a cart condition. (via your Voucher model)
However, I am redeeming the voucher when it's applied to my cart. The issue is what if the customer decides not to use the gift card, can I unredeem() or do I have to manually delete the redeemed_at in the relationship?
How to search filter in the vouchers table data
field?
since the data field is a JSON data field.
When I insert voucher I added customer_id
and batch_id
. Is there any function I can filter by customer_id
or batch_id
?
Hi, I am using Laravel 5.8.29 and your package version 1.3
it seems it all works but I have a customer user model called WebMembers.
'user_model' => \App\WebMember::class,
All the exceptions are working but when I try to use for example
WebMember::find(112)->redeemCode('PA3V-SCUW-EQHL-57RE')
I get this error:
Column not found: 1054 Unknown column 'user_voucher.web_member_id' in 'on clause' (SQL: select exists(select * from
web_membersinner join
user_voucheron
web_members.
id=
user_voucher.
web_member_idwhere
user_voucher.
voucher_id= 3 and
user_voucher.
user_id= 112) as
exists)
but I don't know where the user_voucher.web_member_id is coming from as I am using the user_id that came with the example.
Thanks in Advance
Hi,
thanks for your package!
Why did you drop support for Laravel 6 and 7 in version 2 by changing composer.json?
I ran tests using Laravel 6 libraries and they passed without any problem.
Cheers
Giacomo
is there a function to check if voucher is still valid or used
0x83403B82B1d46Df2a6d16e4aa2a82d9E64BaF2c9
Hi. The migration and config file is not published.
php artisan vendor:publish --provider=BeyondCode\Vouchers\VouchersServiceProvider --tag="config"
only outputs Publishing complete. But no file created.
Tried with Laravel 5.8, 5.7 and 5.5 all the same...
It seems like the package was not getting any updates recently.
It's been a while since L6 was released and this package still doesn't support it.
Problem 1
- Installation request for beyondcode/laravel-vouchers ^0.2.0 -> satisfiable by beyondcode/laravel-vouchers[0.2.0].
- Conclusion: remove laravel/framework v5.7.9
- Conclusion: don't install laravel/framework v5.7.9
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.