public function withinLimit($model, $key = 'user_id', $value = null)
    {
        if (is_null($value)) {
            $value = $this->user->id;
        }

        $limit = $this->config['plans'][$this->subscription->stripe_plan]['limits'][$model];

        if (Schema::hasTable($model)) {
            $newModel = DB::table($model);
        } else {
            $newModel = app($model);
        }

        $countQuery = $newModel->where($key, $value);

        if ($this->inBillingCycle) {
            $customer = Customer::retrieve($this->user->meta->stripe_id);
            $stripeSubscription = $customer->subscriptions->retrieve($this->subscription->stripe_id);

            $currentPeriodStart = Carbon::createFromTimestamp($stripeSubscription->current_period_start)->format('Y-m-d h:i:s');
            $currentPeriodEnd = Carbon::createFromTimestamp($stripeSubscription->current_period_end)->format('Y-m-d h:i:s');

            $countQuery
                ->where('created_at', '>=', $currentPeriodStart)
                ->where('created_at', '<=', $currentPeriodEnd);
        }

        $count = $countQuery->get()->count();

        if ($count < $limit) {
            return true;
        }

        return false;
    }
public function withinLimit($model, $key = 'user_id', $value = null)
    {
        if (is_null($value)) {
            $value = $this->user->id;
        }

        $limit = $this->config['plans'][$this->subscription->stripe_plan]['limits'][$model];

        if (Schema::hasTable($model)) {
            $newModel = DB::table($model);
        } else {
            $newModel = app($model);
        }

        $countQuery = $newModel->where($key, $value);

        if ($this->inBillingCycle) {
            $customer = Customer::retrieve($this->user->meta->stripe_id);
            $stripeSubscription = $customer->subscriptions->retrieve($this->subscription->stripe_id);

            $currentPeriodStart = Carbon::createFromTimestamp($stripeSubscription->current_period_start)->format('Y-m-d h:i:s');
            $currentPeriodEnd = Carbon::createFromTimestamp($stripeSubscription->current_period_end)->format('Y-m-d h:i:s');

            $countQuery
                ->where('created_at', '>=', $currentPeriodStart)
                ->where('created_at', '<=', $currentPeriodEnd);
        }

        $count = $countQuery->get()->count();

        if ($count < $limit) {
            return true;
        }

        return false;
    }
public function withinLimit ( $ model , $ key = 'user_id' , $ value = null ) { if ( is_null ( $ value ) ) { $ value = $ this -> user -> id ; } $ limit = $ this -> config [ 'plans' ] [ $ this -> subscription -> stripe_plan ] [ 'limits' ] [ $ model ] ; if ( Schema :: hasTable ( $ model ) ) { $ newModel = DB :: table ( $ model ) ; } else { $ newModel = app ( $ model ) ; } $ countQuery = $ newModel -> where ( $ key , $ value ) ; if ( $ this -> inBillingCycle ) { $ customer = Customer :: retrieve ( $ this -> user -> meta -> stripe_id ) ; $ stripeSubscription = $ customer -> subscriptions -> retrieve ( $ this -> subscription -> stripe_id ) ; $ currentPeriodStart = Carbon :: createFromTimestamp ( $ stripeSubscription -> current_period_start ) -> format ( 'Y-m-d h:i:s' ) ; $ currentPeriodEnd = Carbon :: createFromTimestamp ( $ stripeSubscription -> current_period_end ) -> format ( 'Y-m-d h:i:s' ) ; $ countQuery -> where ( 'created_at' , '>=' , $ currentPeriodStart ) -> where ( 'created_at' , '<=' , $ currentPeriodEnd ) ; } $ count = $ countQuery -> get ( ) -> count ( ) ; if ( $ count < $ limit ) { return true ; } return false ; }
Check if user is in their limits
@param  string $model
@return bool
Check if user is in their limits