laraplans | SaaS style recurring plans for Laravel | Ecommerce library
kandi X-RAY | laraplans Summary
kandi X-RAY | laraplans Summary
A Laravel package for SaaS style recurring plans.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Record a feature .
- Change subscription plan .
- Determine if a feature can be used .
- Register the package services .
- Get all features .
- Create a new subscription .
- Check if user is subscribed .
- Boot the model .
- Register the plans table .
- Resolve a subscription by name .
laraplans Key Features
laraplans Examples and Code Snippets
Community Discussions
Trending Discussions on laraplans
QUESTION
Im using this package: https://github.com/gerardojbaez/laraplans and the documentation is a little confusing.
The information for the user can be taken from the suscription plan, but not viceversa so I'm having problems when trying to use 2 types (or more) of suscriptions plans.
I have this on my HomeController:
...ANSWER
Answered 2017-Sep-13 at 21:41That's the magic of Laravel.
You get the user model by calling Auth::user() so there you already have the relevant Model that you're looking for. That of the authenticated user.
Now inside the Model-Definition you likely have a method subscription which returns the Related Model. (You probably added some logic for the 'Pro' parameter).
Laravel here is developed with convention-over-configuration in mind and knows which rows in the table actually to look for. So what you need is a 'id' in each table, and due to the relationship a 'user_id' in the table holding the subscriptions. There is a way to define that differently in case. Here is the doc: https://laravel.com/docs/5.4/eloquent-relationships
So you got the plan from the relevant user, I don't see anything bad here.
===
You use $user->subscription but do an ->subscriptions()
instead (notice the plural 's'). Use a loop (or ->first()) since you get plans and not one plan
Right now you always pass 'Pro' in but the authenticated user might now be subscribed to the Pro-Plan and hence returns null. Subscriptions returns the hasMany relation. From there /not tried/ you can loop over the result and get the names of the plan or whatever you need. Notice: It's a hasMany, although the user might just have subscribed to one subscription. So you need to loop or get the first result.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install laraplans
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page