Example #1
0
 /**
  * @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;
 }
Example #2
0
 /**
  * @return $this
  */
 public function resetQueryBuilder()
 {
     $this->specificationQuery = clone $this->table;
     $this->specificationQuery = $this->specificationQuery->newQuery();
     $this->specifications = [];
     return $this;
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * @return $this
  */
 public function newQuery()
 {
     $this->model = $this->model->newQuery();
     return $this;
 }