コード例 #1
0
 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $builder
  * @return void
  */
 public function apply(Builder $builder)
 {
     $model = $builder->getModel();
     $builder->whereNotNull($model->getQualifiedActivatedAtColumn());
     $builder->macro('withDeactivated', function (Builder $builder) {
         $this->remove($builder);
         return $builder;
     });
     $builder->macro('onlyDeactivated', function (Builder $builder) {
         $model = $builder->getModel();
         $this->remove($builder);
         $builder->getQuery()->whereNotNull($model->getQualifiedActivatedAtColumn());
         return $builder;
     });
     $builder->macro('deactivate', function (Builder $builder) {
         $model = $builder->getModel();
         $builder->withDeactivated();
         return $builder->update([$model->getActivatedAtColumn() => null]);
     });
     $builder->macro('activate', function (Builder $builder) {
         $model = $this->getModel();
         $query = $model->newQuery()->where($model->getKeyName(), $model->getKey());
         $model->{$model->getActivatedAtColumn()} = $time = $model->freshTimestamp();
         $query->update([$model->getActivatedAtColumn() => $model->fromDateTime($time)]);
     });
 }
コード例 #2
0
 /**
  * Returns the count for a countable parameter, given the query provided
  *
  * @param string                   $name
  * @param EloquentBuilder          $query
  * @param CountableFilterInterface $filter
  * @return array
  */
 public function count($name, $query, CountableFilterInterface $filter)
 {
     // if the columnname is not set, assume an id field based on a table name
     $columnName = empty($this->columnName) ? $name : $this->columnName;
     if (!$this->includeEmpty) {
         $query->whereNotNull($columnName);
     }
     return $query->select("{$columnName} AS {$this->columnAlias}", DB::raw("{$this->countRaw} AS {$this->countAlias}"))->groupBy($columnName)->pluck($this->countAlias, $this->columnAlias);
 }
コード例 #3
0
ファイル: Clipping.php プロジェクト: atrauzzi/phperclip
 /**
  * Modifies the query to only include files attached to an clippable.
  *
  * @param Builder $query
  * @return Builder
  */
 public function scopeAttached(Builder $query)
 {
     return $query->whereNotNull('clippable_id')->whereNotNull('clippable_type');
 }
コード例 #4
0
ファイル: Subscriber.php プロジェクト: uwm-appbrewery/Cachet
 /**
  * Scope verified subscribers.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeIsVerified(Builder $query)
 {
     return $query->whereNotNull('verified_at');
 }
コード例 #5
0
ファイル: JobCard.php プロジェクト: buys-fran/mtech-mis
 /**
  * Scope a query to only include the jobs that have a due date.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeWithDueDate($query)
 {
     return $query->whereNotNull('job_cards_orig_oc_date')->orWhere('job_cards_new_oc_date', '<>', null);
 }
コード例 #6
0
ファイル: Session.php プロジェクト: umahatokula/academia
 /**
  * Returns all the registered users.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeRegistered(Builder $query)
 {
     return $query->whereNotNull('user_id')->with('user');
 }
コード例 #7
0
ファイル: Group.php プロジェクト: BibleBowl/account
 /**
  * Get groups near a another address.
  *
  * @param Builder $q
  * @param Address $address
  * @param null    $miles
  *
  * @return $this
  */
 public function scopeNear(Builder $q, Address $address, $miles = null)
 {
     if (is_null($miles)) {
         $miles = Config::get('biblebowl.groups.nearby');
     }
     return $q->active()->with(['address' => function ($q) use($miles, $address) {
         $q->whereNotNull($address->getLatColumn())->whereNotNull($address->getLngColumn())->within($miles, 'miles', $address->latitude, $address->longitude);
     }]);
 }
コード例 #8
0
 /**
  * Query filters.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function queryFilters($query, $filters = [])
 {
     $filters = $filters ?: $this->filters;
     foreach ($filters as $key => $filter) {
         foreach ($filter as $operator => $values) {
             $values = is_array($values) ? $values : [$values];
             $operator = is_numeric($operator) ? '=' : $operator;
             if ($operator == '=') {
                 $query->whereIn($key, $values);
             } elseif ($operator == '!=') {
                 $query->whereNotIn($key, $values);
             } elseif ($operator == 'null') {
                 $query->whereNull($key);
             } elseif ($operator == 'not_null') {
                 $query->whereNotNull($key);
             } else {
                 $query->where($key, $operator, head($values));
             }
         }
     }
     return $query;
 }
コード例 #9
0
 /**
  * Add a whereNotNull to the query
  *
  * @param $field
  * @return mixed
  */
 public function whereNotNull($field)
 {
     $this->builder = $this->builder->whereNotNull($field);
     return $this;
 }
コード例 #10
0
ファイル: CanDeactivate.php プロジェクト: BibleBowl/account
 /**
  * Query scope for inactive groups.
  */
 public function scopeInactive(Builder $query)
 {
     return $query->whereNotNull($this->getInactiveColumn());
 }
コード例 #11
0
 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @param  \Illuminate\Database\Eloquent\Model $model
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     $builder->whereNotNull('published_at');
     $this->extend($builder);
 }
コード例 #12
0
ファイル: Filter.php プロジェクト: aginev/search-filters
 /**
  * NotNull
  *
  * @param $key
  * @param $value
  * @return $this
  */
 private function setNotNull($key, $value)
 {
     $this->query->whereNotNull($key, $value);
     return $this;
 }
コード例 #13
0
ファイル: Notification.php プロジェクト: gez-studio/gez-mall
 public function scopeRead(Builder $query)
 {
     $query->whereNotNull('read_at');
 }
コード例 #14
0
ファイル: UserSession.php プロジェクト: linhntaim/katniss
 /**
  * Returns all the registered users.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeLoggedInUsers($query)
 {
     return $query->whereNotNull('user_id')->with('user');
 }
コード例 #15
0
ファイル: NotEmpty.php プロジェクト: czim/laravel-filter
 /**
  * Applies parameter filtering for a given query
  *
  * @param string          $name
  * @param mixed           $value
  * @param EloquentBuilder $query
  * @param FilterInterface $filter
  * @return EloquentBuilder
  */
 public function apply($name, $value, $query, FilterInterface $filter)
 {
     $column = (!empty($this->table) ? $this->table . '.' : null) . (!empty($this->column) ? $this->column : $name);
     return $query->whereNotNull($column)->where($column, '!=', '');
 }