laravelcm / laravel-subscriptions

Laravel Subscriptions is a flexible plans and subscription management system for Laravel.
MIT License
126 stars 20 forks source link

Duplicate Feature Slug #26

Open 200-0K opened 3 weeks ago

200-0K commented 3 weeks ago

I have multiple subscription plans (free, pro, premium), each with features that share the same slug but have different values depending on the plan. When I attempt to save two features with the same slug, a number suffix is added due to the unique constraint on the feature slug. What’s the best way to handle this? Should I create separate feature slugs for each plan, or is there a recommended approach to manage features with shared slugs across plans?

image

harrisonratcliffe commented 1 week ago

I had the same issue. I've forked this project to rebuild it to get rid of this issue so I might publish it if you need it. Plus a few other improvements.

200-0K commented 1 week ago

After searching for too long, I decided to create a package myself since none met my requirements. Feel free to check it out here: https://github.com/200-0K/larasub

Note: It's still under development, so stability is a work in progress.

harrisonratcliffe commented 1 week ago

After searching for too long, I decided to create a package myself since none met my requirements. Feel free to check it out here: https://github.com/200-0K/larasub

Note: It's still under development, so stability is a work in progress.

Nice, does it have the ability to set features to not reset? ie if I wanted a user to have 1 domain, the usage never resets unless its manually removed/reset?

200-0K commented 1 week ago

Nice, does it have the ability to set features to not reset? ie if I wanted a user to have 1 domain, the usage never resets unless its manually removed/reset?

Yes you can. Plan's features can be resetable by period or fixed until the end of a subscription

harrisonratcliffe commented 1 week ago

Nice, does it have the ability to set features to not reset? ie if I wanted a user to have 1 domain, the usage never resets unless its manually removed/reset?

Yes you can. Plan's features can be resetable by period or fixed until the end of a subscription

Oh I had a look your docs but I can't find a way to set a single feature reset period to fixed. How is that achieved?

200-0K commented 1 week ago

Nice, does it have the ability to set features to not reset? ie if I wanted a user to have 1 domain, the usage never resets unless its manually removed/reset?

Yes you can. Plan's features can be resetable by period or fixed until the end of a subscription

Oh I had a look your docs but I can't find a way to set a single feature reset period to fixed. How is that achieved?

Updated 👍

Basic Usage > Create a Plan

In the example, the Plan includes three features. The first feature has a reset period of 1 day. The other two, since the resetPeriod method wasn't explicitly called, will remain fixed throughout the subscription period

harrisonratcliffe commented 1 week ago

Nice, does it have the ability to set features to not reset? ie if I wanted a user to have 1 domain, the usage never resets unless its manually removed/reset?

Yes you can. Plan's features can be resetable by period or fixed until the end of a subscription

Oh I had a look your docs but I can't find a way to set a single feature reset period to fixed. How is that achieved?

Updated 👍

Basic Usage > Create a Plan

In the example, the Plan includes three features. The first feature has a reset period of 1 day. The other two, since the resetPeriod method wasn't explicitly called, will remain fixed throughout the subscription period

Nice one mate, in that case I think I'll use yours instead.

harrisonratcliffe commented 1 week ago

Nice, does it have the ability to set features to not reset? ie if I wanted a user to have 1 domain, the usage never resets unless its manually removed/reset?

Yes you can. Plan's features can be resetable by period or fixed until the end of a subscription

Oh I had a look your docs but I can't find a way to set a single feature reset period to fixed. How is that achieved?

Updated 👍

Basic Usage > Create a Plan

In the example, the Plan includes three features. The first feature has a reset period of 1 day. The other two, since the resetPeriod method wasn't explicitly called, will remain fixed throughout the subscription period

I'll modify the package though so there is an option to create a price_id column on tables, useful for getting the product/price from Stripe or Paddle for example to charge the client. I'll submit a PR request unless you do that before me :)

200-0K commented 1 week ago

Feel free to modify the package as you see fit! However, I intentionally built it to focus only on subscriptions and not include payment-related functionality. This design keeps the package lightweight and flexible, making it easier to integrate with other packages

I actually created another package called Laratransaction, which focuses solely on payment transactions, and I’ve successfully integrated it with the Larasub package without modifying its tables

Integration can be done by extending the base class:

use Err0r\Larasub\Models\Subscription as Base;
use Err0r\Laratransaction\Traits\HasTransaction;

class Subscription extends Base
{
    use HasTransaction;
}