/** * Add the restore extension to the builder. * * @param \Illuminate\Database\Eloquent\Builder $builder * @return void */ protected function addRestore(Builder $builder) { $builder->macro('restore', function (Builder $builder) { $builder->withTrashed(); return $builder->update([$builder->getModel()->getDeletedAtColumn() => 'publish']); }); }
/** * 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; }
/** * Reset and includes soft deletes for following queries. * * @return $this */ public function startWithTrashed() { /** * Save to conditons. */ $this->addCondition('withTrashed', 'withTrashed'); $this->model = $this->model->withTrashed(); return $this; }
/** * Reset and includes soft deletes for following queries. * * @return $this */ public function startWithTrashed() { $this->reset(new Action(__METHOD__, [])); /** * Save to conditons. */ $this->addCondition('withTrashed', 'withTrashed'); $this->model = $this->model->withTrashed(); return $this; }
/** * Return trashed models with query if told so * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ protected function useWithTrashed(Builder $query) { if ($this->withTrashed && $query->getMacro('withTrashed') !== null) { return $query->withTrashed(); } return $query; }
/** * Scope a query to only include activities that are completed. * * @param \Illuminate\Database\Eloquent\Builder $query the query to activities to be scoped * @return \Illuminate\Database\Eloquent\Builder */ public function scopeCompleted($query) { $query->withTrashed()->join('tasks', 'activities.activity_id', '=', 'tasks.activity_id')->where('tasks.status', 'completed')->latest('datetime_start'); }
/** * Restore all of the soft deleted related models. * * @return int */ public function restore() { return $this->query->withTrashed()->restore(); }
/** * Paginate all deleted posts. * * @param int $postsPerPage * * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection */ public function paginateAllDeleted($postsPerPage) { return $this->model->withTrashed()->paginate($postsPerPage); }
/** * By default a soft-deleted model does not return trashed. Use this * method to also fetch soft-deleted entries. * * @return $this */ public function withTrashed() { $this->builder = $this->builder->withTrashed(); return $this; }