andersao / andersao/l5-repository
BaseRepository::update() resetModel problem
- 主要言語
- PHP
- スター
- 4.2k
- フォーク
- 880
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I write a bulk update function, which update multiple models in one request, each update has a result message and do not affect others' execution. I reuse the same repository in the controller since if everything is alright, each call of Repository::update() will `resetModel()` in the end.
However, because BaseRepository::update() use `$model = $this->model->findOrFail($id);`, if throwing ModelNotFound exception, the `resetModel() ` will not be executed, and repository model is polluted, if we forget to `resetModel ()` manually, later operations of this repository will cause unexpected problem.
So, is it better to put `resetModel()` in a finally section to guarantee it will be called in the end for update()? such as
~~~php
try {
$this->applyScope();
// ...
} finally {
$this->resetModel();
}
~~~
コントリビューションガイド
評価
この issue はまだ評価されていません。