andersao / andersao/l5-repository

BaseRepository::update() resetModel problem

Aberta
#583 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
PHP
Estrelas
4.2k
Forks
880
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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();
}

~~~

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.