GithubHelp home page GithubHelp logo

laravel-vouchers's Issues

Optional model relation

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.

Custom relation table name

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 ``

Instructions for publishing config file appear incorrect

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 error in laravel 5.8.14

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

Config not Publishing

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.

No pre-apply condition

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

Feature: add the possibility to redeem vouchers multiple times with limit

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:

  1. Migration
 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();
        });
  1. Model
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;
    }
}

Your requirements could not be resolved to an installable set of packages. not support laravel (v9.3.2)?

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.

Is there a way to Un-Redeem? or a way to check if voucher exists without redeeming?

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?

Custom User model

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 joinuser_voucheronweb_members.id=user_voucher.web_member_idwhereuser_voucher.voucher_id= 3 anduser_voucher.user_id= 112) asexists)

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

Support for Laravel 6 and 7?

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

Funds

0x83403B82B1d46Df2a6d16e4aa2a82d9E64BaF2c9

Package does not publish migration and config file

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...

Is this project dead?

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.

Not compatible with L5.7.9

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

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.