2017 © Pedro Peláez
 

library laravel-subscription

Laravel 订阅模块,用于有时间限制的服务订阅

image

goodwong/laravel-subscription

Laravel 订阅模块,用于有时间限制的服务订阅

  • Monday, August 28, 2017
  • by goodwong
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel 5 Subscription

订阅模块,用于有时间限制的服务订阅, (*1)

安装

  1. 通过composer安装, (*2)

    composer require goodwong/laravel-subscription
    
  2. 打开config/app.php,在providers数组里注册服务:, (*3)

    Goodwong\LaravelSubscription\SubscriptionServiceProvider::class,
    
  3. 创建数据库, (*4)

    php artisan migrate
    

操作

  1. 为用户添加订阅服务(在相同type下,若用户已经有效订阅,则会自动删除旧的订阅) php $handler = app('Goodwong\LaravelSubscription\Handlers\SubscriptionHandler'); $subscription = $handler->subscribe($user_id, $level = 'basic', $days = 30, $config = [ 'type' => 'plan', 'start_at' => '2017-05-05 08:00:59', 'comment' => '', ]);
  2. 查询订阅, (*5)

    // 有global scope限定start_at/end_at
    Goodwong\LaravelSubscription\Entities\Subscription::where('user_id', $user_id)->first();
    // 查询所有订阅(包含已经归档的)
    Goodwong\LaravelSubscription\Entities\Subscription::withoutGlobalScopes()->withTrashed()->get();
    
  3. 与User结合, (*6)

    <?php
    
    namespace App\User\Entities;
    
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Database\Eloquent\Builder;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    
    class User extends Authenticatable
    {
        use Notifiable;
    
        /**
         * membership
         */
        public function plan()
        {
            return $this->hasOne('Goodwong\LaravelSubscription\Entities\Subscription')
                // ->where('type', 'plan')
                ->orderBy('id', 'desc')
                ;
        }
    
        /**
         * The "booting" method of the model.
         *
         * @return void
         */
        protected static function boot()
        {
            parent::boot();
    
            static::addGlobalScope('plan', function (Builder $builder) {
                $builder->with('plan');
            });
        }
    }
    

The Versions

28/08 2017

dev-master

9999999-dev

Laravel 订阅模块,用于有时间限制的服务订阅

  Sources   Download

MIT

17/06 2017

v1.0.0

1.0.0.0

Laravel 订阅模块,用于有时间限制的服务订阅

  Sources   Download

MIT