andersao / andersao/l5-repository

BaseRepository::update() resetModel problem

オープン
#583 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
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 はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。