PHP code example of goodwong / laravel-subscription

1. Go to this page and download the library: Download goodwong/laravel-subscription library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goodwong / laravel-subscription example snippets


    Goodwong\LaravelSubscription\SubscriptionServiceProvider::class,
    

    $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' => '',
    ]);
    

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

    
    
    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');
            });
        }
    }
    
shell
    php artisan migrate