Пример #1
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;
 }
Пример #2
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;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * Retrieve all data of repository deleted
  *
  * @param array $columns
  *
  * @return mixed
  */
 public function onlyTrashed($columns = ['*'])
 {
     $this->applyCriteria();
     $this->applyScope();
     if ($this->model instanceof Builder) {
         $results = $this->model->onlyTrashed()->get($columns);
     } else {
         $results = $this->model->onlyTrashed()->get($columns);
     }
     $this->resetModel();
     $this->resetScope();
     return $this->parserResult($results);
 }
 /**
  * Empty trash
  *
  * @param int $day
  * @return array $ids
  */
 public function emptyTrash($day = 60)
 {
     //Convert day to carbon object
     $date = Carbon::now()->subDays($day);
     //Prepare the query to get only trash
     $query = $this->model->onlyTrashed();
     //Archived since
     $query->where('deleted_at', '<', $date->toDateTimeString());
     //Execute the query
     $trash = $query->get();
     //By default, no ids
     $ids = [];
     //For each results, add ids
     foreach ($trash as $result) {
         $ids[] = $result->id;
     }
     //If we have archive to delete
     if (!empty($ids)) {
         $this->db->table($this->model->getTable())->whereIn('id', $ids)->delete();
     }
     return $ids;
 }
 /**
  * @param Model      $model
  * @param Repository $repository
  *
  * @return mixed
  */
 public function apply(Model $model, Repository $repository)
 {
     return $model->onlyTrashed();
 }