/**
  * 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']);
     });
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * 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;
 }