/** * Remove the scope from the given Eloquent query builder. * * @param \Illuminate\Database\Eloquent\Builder $builder * @param \Illuminate\Database\Eloquent\Model $model * * @return void */ public function remove(Builder $builder, Model $model) { $column = $model->getQualifiedDeletedAtColumn(); $query = $builder->getQuery(); foreach ((array) $query->wheres as $key => $where) { // If the where clause is a soft delete date constraint, we will remove it from // the query and reset the keys on the wheres. This allows this developer to // include deleted model in a relationship result set that is lazy loaded. dd($where); if ($this->isSoftDeleteConstraint($where, 'type')) { unset($query->wheres[$key]); $query->wheres = array_values($query->wheres); } } }
/** * Remove the scope from the given Eloquent query builder. * * @param \Illuminate\Database\Eloquent\Builder $builder * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function remove(Builder $builder, Model $model) { $column = $model->getQualifiedDeletedAtColumn(); $query = $builder->getQuery(); $query->wheres = collect($query->wheres)->reject(function ($where) use($column) { return $this->isSoftDeleteConstraint($where, $column); })->values()->all(); $bindings = $query->getRawBindings(); foreach ($bindings['where'] as $k => $v) { if ($v !== 'trash') { continue; } unset($bindings['where'][$k]); break; } $query->setBindings($bindings['where']); }
/** * Force the result set to only included soft deletes. * * @return \Illuminate\Database\Eloquent\Builder|static */ public function onlyTrashed() { $this->withTrashed(); $this->query->whereNotNull($this->model->getQualifiedDeletedAtColumn()); return $this; }