Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get user subscription on planSubscription('main') function #23

Open
syntx1997 opened this issue Oct 9, 2024 · 3 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@syntx1997
Copy link

Hello guys, I am really having trouble getting the user subscription, it always returns null even though the user was subscribed already, I have checked the sdubscriptions table on database and the user's id was there. It only happens on live server, no issue on local.

@syntx1997
Copy link
Author

Sorry, I just want to give some updates about my investigation about this. I think it is something related to this: $user->planSubscription('main')->getFeatureRemainings('listings'); the value main is actually from the slug field from the subscriptions table.

Subscriptions table:
Screenshot 2024-10-09 at 10 28 47 PM

I have checked the planSubscription function inside the HasPlanSubscriptions trait and this is what I found. I think this is the main reason for this. It's just happen that I only tested one subscription on my local (which means there's only one subscription data there with main slug) thats why this bug didn't show up.
Screenshot 2024-10-09 at 10 30 50 PM

@syntx1997
Copy link
Author

syntx1997 commented Oct 9, 2024

I solve it by overriding the function by recreating a function on my User model where the trait has been applied.

public function planSubscription(string $subscriptionSlug): ?Subscription { return $this->planSubscriptions()->where('slug', 'like', '%' . $subscriptionSlug . '%')->first(); }

@syntx1997 syntx1997 changed the title Can't get user plan when on live server Can't get user subscription on planSubscription('main') function Oct 9, 2024
@Redleks
Copy link

Redleks commented Oct 24, 2024

Hi!
I faced the same problem. It was an absolutely strange solution with unique slugs. I had to use my own class for features. I overwrite getSlugOptions function

public function getSlugOptions(): SlugOptions
    {
        return SlugOptions::create()
            ->doNotGenerateSlugsOnUpdate()
            ->generateSlugsFrom('name')
            ->saveSlugsTo('slug')
            ->extraScope(fn($builder) => $builder->where('plan_id', $this->plan_id));
    }

And remove unique key for slug in DB. My solution allows you to make a unique slug for a separate plan.

@mckenziearts mckenziearts added the bug Something isn't working label Nov 1, 2024
@mckenziearts mckenziearts self-assigned this Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants