michael-rubel / laravel-couponables Goto Github PK
View Code? Open in Web Editor NEWCoupons/promocodes leveraging Eloquent's polymorphic relationships
License: MIT License
Coupons/promocodes leveraging Eloquent's polymorphic relationships
License: MIT License
i want to give users the oppourtunity to check if coupon is still valid, before user redeem, but my code isnt working
public $code;
public function check($id)
{
$user = User::find($id);
$user->verifyCouponOr($this->code, function ($exception) {
throw ValidationException::withMessages(['code' => 'Your coupon code is already use',]);
});
$user->isCouponAlreadyUsed($this->code);
}
blade
<div class="my-5">
<div class="bg-white rounded-md p-3 mx-2">
<form wire:submit="check({{ auth()->user()->id }})" action="" class="space-y-3">
<input wire:model="code" placeholder="Check If Coupon Is Valid" type="text" class="px-4 py-2 rounded-md w-full">
<button class="bg-blue-500 rounded-md py-2 px-3">Check Coupon</button>
</form>
@error($code)
{{ $message }}
@enderror
</div>
</div>
my coupon:
redeemer_type: App\Models\Member,
redeemer_id: 30,
$redeemer = Member::find(18);
$redeemer->verifyCoupon($coupon_code); //return no exception
no matter which redeemer it is, always pass the validation.
i found the issue in this function.
public function isAllowedToRedeemBy(Model $redeemer): bool
{
return with(static::$bindable, function ($coupon) use ($redeemer) {
if ($coupon->isMorphColumnsFilled() && ! $coupon->redeemer?->is($redeemer)) {
return false;
}
if ($coupon->isOnlyRedeemerTypeFilled() && ! $coupon->isSameRedeemerModel($redeemer)) {
return false;
}
return true;
});
}
$coupon is always null inside this function >> $coupon->redeemer_type and $coupon->redeemer_id are null >> always return true.
and if i use $this instead of static::$bindable, everything works.
Please help to fix this issue, thanks!
Hi,
I try this code
$user->verifyCouponOr("ABC123", function($exception){
dump($exception);
});
I expected the output will be the exception (e.g MichaelRubel\Couponables\Exceptions\OverQuantityException The coupon is exhausted.
)
.
but instead, it return the coupon code:
"ABC123"
.
I encountered error with this line.
$course->coupons()->get();
Column not found: 1054 Unknown column 'couponables.couponable_id' in 'field list'
Simple solution would be to rename column name in couponables
table.
Rename the morph field couponables
to couponable
?
i want to all users to create coupon and also get the list of coupon created them
I assigned the coupon to $redeemer by saving
redeemer_type=members
redeemer_id=46 (in this case)
I try to use another member to verifyCoupon the coupon and it returns true
$member = Member::find(47);
$coupon = $member->verifyCoupon($code); << it return no exception
I want to get all coupons with redeemer
like:
Coupon::with(['redeemer'])->get();
thanks.
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.