private function applyFilters(Builder $query, $expression, $value, $multiple = false)
 {
     $equalsFilter = false;
     $field = null;
     $filter = explode(":", $expression);
     // filter[field:filter]=value
     if (count($filter) == 2) {
         $field = $filter[0];
         $filter = $filter[1];
     } else {
         $equalsFilter = true;
         $field = $expression;
     }
     // filter[field]=value
     if ($equalsFilter) {
         $multiple ? $query->orWhere($field, '=', $value) : $query->where($field, '=', $value);
     }
     // filter[field:between]=A,B
     if ($this->isBetweenFilter($filter)) {
         $betweenValues = $this->getBetweenValues($value);
         if (count($betweenValues) != 2) {
             throw new BadRequestHttpException("Please specify two numbers to filter between");
         }
         $multiple ? $query->orWhereBetween($field, $betweenValues) : $query->whereBetween($field, $betweenValues);
     }
     // filter[field:[after, before, greater_than, less_than]]=value
     if ($this->isComparisonFilter($filter)) {
         if ($this->isDateFilter($field)) {
             $value = Carbon::createFromTimestamp($value);
         }
         $comparisonFilter = $this->getComparisonFilter($filter);
         $multiple ? $query->orWhere($field, $comparisonFilter, $value) : $query->where($field, $comparisonFilter, $value);
     }
     // filter[field:[contains, ends_with, starts_with]]=value
     if ($this->isWildcardFilter($filter)) {
         $value = $this->getLikeWildcard($filter, $value);
         $multiple ? $query->orWere($field, 'like', $value) : $query->where($field, 'like', $value);
     }
     // filter[field:trashed]=true
     if ($this->isTrashedFilter($field)) {
         $query->onlyTrashed();
     }
 }
Example #2
0
 /**
  * Apply soft-delete changes to the query.
  *
  * @param Model|Builder $query
  * @return mixed
  */
 protected function applySoftDeletesQuery($query)
 {
     if ($this->withTrashed === true) {
         return $query->withTrashed();
     } elseif ($this->onlyTrashed === true) {
         return $query->onlyTrashed();
     }
     return $query;
 }
Example #3
0
 /**
  * Reset and only includes soft deletes for following queries.
  *
  * @return $this
  */
 public function startWithTrashedOnly()
 {
     /**
      * Save to conditons.
      */
     $this->addCondition('onlyTrashed', 'onlyTrashed');
     $this->model = $this->model->onlyTrashed();
     return $this;
 }
 /**
  * Reset and only includes soft deletes for following queries.
  *
  * @return $this
  */
 public function startWithTrashedOnly()
 {
     $this->reset(new Action(__METHOD__, []));
     /**
      * Save to conditons.
      */
     $this->addCondition('onlyTrashed', 'onlyTrashed');
     $this->model = $this->model->onlyTrashed();
     return $this;
 }
 /**
  * Scope a query to only include activities that are cancelled/soft deleted.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query  the query to activities to be scoped
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeCancelled($query)
 {
     $query->onlyTrashed()->latest('datetime_start');
 }
 /**
  * Handle the query.
  *
  * @param TableBuilder $builder
  * @param Builder      $query
  */
 public function handle(TableBuilder $builder, Builder $query)
 {
     $query->onlyTrashed();
 }