devrheber / laravel-subscriptions
一个简单的订阅包
dev-master
2022-11-23 23:13 UTC
Requires
- php: ^8.0
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: 3.8.*
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-24 03:14:47 UTC
README
一个简单的Laravel订阅包。
欢迎所有建议,请将您的问题发送至:在这里提交问题
安装
您可以通过Composer安装此包
**此包在Laravel 7或更高版本中运行,因为
composer require devrheber/laravel-subscriptions
注册服务提供者
将Devrheber\LaravelSubscriptions\LaravelSubscriptionsServiceProvider::class
添加到您的config/app.php
文件中
'providers' => [ /** * Some Providers */ Devrheber\LaravelSubscriptions\LaravelSubscriptionsServiceProvider::class ]
配置文件和迁移
使用以下命令发布包配置文件和迁移
php artisan vendor:publish --provider="Sagitarius29\LaravelSubscriptions\LaravelSubscriptionsServiceProvider"
然后运行迁移
php artisan migrate
功能概述
- 创建计划和其功能或消耗品。(消耗品处于开发中)
- 管理您的计划:获取所有计划、禁用、删除等。
- 您的用户可以订阅一个计划。
- 用户可以续订、取消、升级或降级其订阅。
- 现在对计划进行分组非常简单。
- 更多功能
一些示例
配置您的用户模型以使用订阅
<?php use Sagitarius29\LaravelSubscriptions\Traits\HasSubscriptions; class User extends Authenticable { use HasSubscriptions; // Add this line for use subscriptions
创建一个具有功能的计划
<?php use Sagitarius29\LaravelSubscriptions\Entities\Plan; use Sagitarius29\LaravelSubscriptions\Entities\PlanFeature; use \Sagitarius29\LaravelSubscriptions\Entities\PlanConsumable; use Sagitarius29\LaravelSubscriptions\Entities\PlanInterval; $plan = Plan::create( 'name of plan', //name 'this is a description', //description 1 // sort order ); $features = [ PlanFeature::make('listings', 50), PlanFeature::make('pictures_per_listing', 10), PlanFeature::make('listing_duration_days', 30), PlanFeature::make('listing_title_bold', true), PlanConsumable::make('number_of_contacts', 10), ]; // adding features to plan $plan->features()->saveMany($features); $plan->isFree(); // return true; // adding interval of price $interval = PlanInterval::make(PlanInterval::MONTH, 1, 4.90); $plan->setInterval($interval); $plan->isFree(); // return false; $plan->isNotFree(); // return true;
用户可以订阅一个计划
<?php use Sagitarius29\LaravelSubscriptions\Entities\Plan; $user = \Auth::user(); $plan = Plan::find(1); $user->subscribeTo($plan); $user->hasActiveSubscription(); // return true; $currentSubscription = $user->getActiveSubscription(); // return Subscription object;
升级或降级订阅
<?php use Sagitarius29\LaravelSubscriptions\Entities\Plan; $user = \Auth::user(); $firstPlan = Plan::find(1); $secondPlan = Plan::find(2); //upgrade or downgrade depending of the price $user->changePlanTo($secondPlan);
取消订阅
<?php $user = \Auth::user(); // the subscription is will end in the expiration date $user->unsubscribe(); // the subscription end now $user->forceUnsubscribe();
测试
composer test
变更日志
请参阅CHANGELOG以获取更多信息,了解最近发生了哪些变化。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件ronnie.adolfo@gmail.com联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。