diff --git a/src/Repositories/BaseRepository.php b/src/Repositories/BaseRepository.php index 8289f1f..5b59b5c 100644 --- a/src/Repositories/BaseRepository.php +++ b/src/Repositories/BaseRepository.php @@ -95,6 +95,10 @@ public function resetModel() $this->makeModel(); } + public function lists($column, $key = null) + { + $this->applyConditions(); + } /** * 根据主键查询 @@ -356,9 +360,10 @@ public function paginate($columns = ['*'], $limit = 0) */ public function create(array $attributes) { - $result = $this->model->create($attributes); + $model = $this->model->newInstance($attributes); + $model->save(); $this->resetModel(); - return $result; + return $model; } /** @@ -386,10 +391,13 @@ public function createBatch(array $attributes) */ public function updateById(array $attributes, int $id) { - $model = $this->model->find($id); - $result = $model->update($attributes); + $model = $this->model->findOrFail($id); + + $model->fill($attributes); + $model->save(); + $this->resetModel(); - return $result; + return $model; } /** @@ -498,8 +506,8 @@ public function updateBatch(array $multipleData = []): bool public function deleteById(int $id) { $model = $this->find($id); - $result = $model->delete(); $this->resetModel(); + $result = $model->delete(); return $result; } @@ -885,7 +893,7 @@ public function commit() DB::commit(); } - + /** * 打印sql语句 * @param Closure $callback @@ -904,4 +912,14 @@ public function getQuerySql(Closure $callback, string $tableName = '') } } + /** + * @param $method + * @param $arguments + * @return mixed + */ + public function __call($method, $arguments) + { + return call_user_func_array([$this->model, $method], $arguments); + } + }