/** * 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) { if (!UserUtils::hasDisplayAllStatus()) { $builder->where($model->getQualifiedStatusColumn(), true); } $this->extend($builder); }
/** * 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) { if (!UserUtils::hasDisplayAllStatus()) { $builder->where($model->getQualifiedStatusColumn(), true); $query = $builder->getQuery(); $this->where_index = count($query->wheres) - 1; $this->binding_index = count($query->getRawBindings()['where']) - 1; } $this->extend($builder); }
/** * Remove the scope from the given Eloquent query builder. * * (This method exists in order to achieve compatibility with laravel 5.1.*) * * @param \Illuminate\Database\Eloquent\Builder $builder * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function remove(Builder $builder, Model $model) { $column = $model->getQualifiedStatusColumn(); $query = $builder->getQuery(); $bindingKey = 0; foreach ((array) $query->wheres as $key => $where) { if ($this->isModerationConstraint($where, $column)) { $this->removeWhere($query, $key); // Here SoftDeletingScope simply removes the where // but since we use Basic where (not Null type) // we need to get rid of the binding as well $this->removeBinding($query, $bindingKey); } // Check if where is either NULL or NOT NULL type, // if that's the case, don't increment the key // since there is no binding for these types if (!in_array($where['type'], ['Null', 'NotNull'])) { $bindingKey++; } } }