Get the name of the "where in" method for eager loading.

@param  \Illuminate\Database\Eloquent\Model  $model
@param  string  $key
@return string
178651
protected function whereInMethod(Model $model, $key)
    {
        return $model->getKeyName() === last(explode('.', $key))
                    && $model->getIncrementing()
                    && in_array($model->getKeyType(), ['int', 'integer'])
                        ? 'whereIntegerInRaw'
                        : 'whereIn';
    }
1196607
private function buildQuery(Model $model = null)
    {
        $query = $this->model->collections();

        $query = $query->whereCollectionName($this->collectionName);

        if ($model) {
            $query = $query->where('item_id', $model->id)
                           ->where('item_type', get_class($model));
        }

        if (!$model && $this->itemType) {
            $query = $query->where('item_type', '=', $this->itemType);
        }

        return $query;
    }
1158126
public function hasRelatedKey($key, $model = false)
    {
        if (!$model) {
            $model = $this->model;
        }

        if (($methodBreaker = strpos($key, '.')) !== false) {
            $method = substr($key, 0, $methodBreaker);
            if (method_exists($model, $method)) {
                return true;
            }
        }

        return false;
    }
1251511
public static function get(Model $model)
    {
        return Mention::where('model_type', get_class($model))
            ->where('model_id', $model->getKey())
            ->get();
    }
1026016
protected function prepareQuery($model)
    {
        // Set the relationships that should be eager loaded
        if (! empty($this->relations)) {
            $model = $model->with($this->relations);
        }

        // Add a basic where clause to the query
        foreach ($this->where as $where) {
            list($attribute, $operator, $value, $boolean) = array_pad($where, 4, null);

            $model = $model->where($attribute, $operator, $value, $boolean);
        }

        // Add a "where in" clause to the query
        foreach ($this->whereIn as $whereIn) {
            list($attribute, $values, $boolean, $not) = array_pad($whereIn, 4, null);

            $model = $model->whereIn($attribute, $values, $boolean, $not);
        }

        // Add a "where not in" clause to the query
        foreach ($this->whereNotIn as $whereNotIn) {
            list($attribute, $values, $boolean) = array_pad($whereNotIn, 3, null);

            $model = $model->whereNotIn($attribute, $values, $boolean);
        }

        // Set the "offset" value of the query
        if ($this->offset > 0) {
            $model = $model->offset($this->offset);
        }

        // Set the "limit" value of the query
        if ($this->limit > 0) {
            $model = $model->limit($this->limit);
        }

        // Add an "order by" clause to the query.
        if (! empty($this->orderBy)) {
            list($attribute, $direction) = $this->orderBy;

            $model = $model->orderBy($attribute, $direction);
        }

        return $model;
    }
31683
protected function getDefaultFor(Model $model)
    {
        if (! $this->withDefault) {
            return;
        }

        $instance = $this->related->newInstance()->setAttribute(
            $this->getForeignKeyName(),
            $model->getAttribute($this->localKey)
        );

        if (is_callable($this->withDefault)) {
            return call_user_func($this->withDefault, $instance) ?: $instance;
        }

        if (is_array($this->withDefault)) {
            $instance->forceFill($this->withDefault);
        }

        return $instance;
    }
681126
protected function getScopeConstraints(Model $model)
    {
        $builder = $model->newQueryWithoutScopes();

        $this->apply($builder, $model);

        return (array) $builder->getQuery()->wheres;
    }
251471
public static function isFunction($model, $key) {
        $nombreLlamar = "";
        if (is_callable([$model, $key], true, $nombreLlamar) && method_exists($model, $key)) {
            $refClass = new \ReflectionClass($model);
            $refFunc = $refClass->getMethod($key);
            //$refFunc = new \ReflectionFunction($nombreLlamar);
            return $refFunc->getNumberOfParameters();
        } else {
            return false;
        }
    }
1191191
protected function getModel($key)
    {
        if (!array_key_exists($key, $this->models)) {
            list($namespace, $key) = $this->splitNamespaceAndKey($key);

            $this->models[$key] = Config::query()
                                        ->where(Config::FIELD_NAMESPACE, $namespace)
                                        ->where(Config::FIELD_KEY, $key)
                                        ->first();

            // Cache if data is found in database
            if ($this->models[$key] !== null) {
                $this->cache->forever($key, $this->models[$key]->value);
            }
        }

        return $this->models[$key];
    }
609169
public function readCache(Model $model, $keys)
    {
        return Cache::read($this->cacheKey($model, $keys), $this->settings[$model->alias]['cacheConfig']);
    }
963074
public function relatedKey($key, $model = false)
    {
        if (!$model) {
            $model = $this->model;
        }

        if (($methodBreaker = strpos($key, '.')) !== false) {
            $method = substr($key, 0, $methodBreaker);
            if (method_exists($model, $method)) {
                if (method_exists($model->$method, $submethod = str_replace($method.'.', '', $key))) {
                    return $model->$method->$submethod();
                }

                if (isset($model->$method->$submethod)) {
                    return $model->$method->$submethod;
                }

                return $model->getRelationValue($method);
            }
        }

        return false;
    }
224381
protected function getReference(Model $model)
    {
        $reference = $this->getReferenceValue($model);

        return $this->wrapWithLink($reference, $this->getLinkForReferenceModel($model));
    }
186233
public function clause($key, $method, $model = null)
    {
        $query = null;

        if (! is_null($model)) {
            $appModel = app($model);
            $query = DB::table(app($model)->table);

            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');

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

        $clause = $this->config['plans'][$this->subscription->stripe_plan][$key];

        return $method($this->user, $this->subscription, $clause, $query);
    }
897889
protected function findModel()
    {
        $class = $this->model;
        $query = $class::query();

        foreach ($this->input as $key => $value) {
            $where = is_array($value) ? 'whereIn' : 'where';
            $query->$where($key, $value);
        }

        return $query->get();
    }
615161
protected function determineModelReferenceSource(Model $model)
    {
        $source = $this->getReferenceSource($model);

        // If we have no source to fall back on at all, use the model key
        if ( ! $source) {
            $source = $model->getKeyName();
        }

        return $source;
    }
416888
public function recordWhereCacheSave($model, $where, $value) {
        /* @var $t Record */
        $t = new $model;
        $cacheKeys = $t->cacheKeys();
        if (!$cacheKeys) {
            return null;
        }
        ksort($where);
        $cache_key = "";
        $key = implode(",", array_keys($where));
        foreach ($cacheKeys as $cacheKey) {
            $m = explode(',', $cacheKey);
            sort($m);
            $cacheKey = implode(",", $m);
            if ($key == $cacheKey) {
                $cache_key = "record_" . $model . "_" . $key . "_" . implode(",", array_values($where));
                break;
            }
        }
        if ($cache_key) {
            Cache::set($cache_key, $value);
        }
        return null;
    }
555900
protected function getFromCasts(Model $model, $key)
    {
        $casts = $this->getCasts($model);

        if (!isset($casts[$key])) {
            return '';
        }

        $cast = $casts[$key];

        foreach ($this->xTypeToCasts as $xType=>$casts) {
            if (in_array($cast, $casts)) {
                return $xType;
            }
        }

        return 'string';
    }