GithubHelp home page GithubHelp logo

michael-rubel / laravel-couponables Goto Github PK

View Code? Open in Web Editor NEW
179.0 4.0 8.0 398 KB

Coupons/promocodes leveraging Eloquent's polymorphic relationships

License: MIT License

PHP 100.00%
laravel php looking-for-contributors coupon coupon-code-generator coupon-service coupons

laravel-couponables's People

Contributors

dependabot[bot] avatar michael-rubel avatar syamsoul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-couponables's Issues

check if coupon is valid

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>

isAllowedToRedeemBy cannot check the owner

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!

verifyCouponOr doesn't return exceptions

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"

.

Unknown column 'couponables.couponable_id'

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 ?

Dose not check the owner of the coupon

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.