/** * @return Builder */ public function newQuery() { if (is_string($this->modelClass)) { return (new $this->modelClass())->newQuery(); } if ($this->modelClass instanceof Model) { return $this->modelClass->newQuery(); } return $this->modelClass; }
/** * @return $this */ public function resetQueryBuilder() { $this->specificationQuery = clone $this->table; $this->specificationQuery = $this->specificationQuery->newQuery(); $this->specifications = []; return $this; }
/** * @param $id * @param $data * @param bool $orFail * @return mixed * * updates an existing record */ public function update($id, $data, $orFail = false) { if ($id instanceof Model) { $this->model = $id; } else { $this->model = new $this->modelClass(); $table = $this->model->getTable(); $this->model = $this->model->newQuery(); $this->model->where($table . '.' . $this->identifier, '=', $id); $this->model = $orFail ? $this->model->firstOrFail() : $this->model->first(); if (!$this->model) { return false; } } if (!is_array($data)) { $data = $this->extractData($data); } $this->model->fill($data); foreach ($this->updateDefaults() as $key => $value) { $this->model->{$key} = $value; } $this->model->save(); return $this->model; }
/** * @return $this */ public function newQuery() { $this->model = $this->model->newQuery(); return $this; }