| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Module\Transaction\Repositorys;
- use App\Module\Test\Models\Test;
- class TestRepository
- {
- protected Test $model;
- public function __construct(Test $model)
- {
- $this->model = $model;
- }
- /**
- * 查找记录
- *
- * @param int $id
- * @return Test|null
- */
- public function find(int $id): ?Test
- {
- return $this->model->find($id);
- }
- /**
- * 创建记录
- *
- * @param array $data
- * @return Test
- */
- public function create(array $data): Test
- {
- return $this->model->create($data);
- }
- /**
- * 更新记录
- *
- * @param int $id
- * @param array $data
- * @return bool
- */
- public function update(int $id, array $data): bool
- {
- $model = $this->find($id);
- if (!$model) {
- return false;
- }
- return $model->update($data);
- }
- /**
- * 删除记录
- *
- * @param int $id
- * @return bool
- */
- public function delete(int $id): bool
- {
- $model = $this->find($id);
- if (!$model) {
- return false;
- }
- return $model->delete();
- }
- }
|