andersao / andersao/l5-repository

Overriding the find method

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

Descrição

I needed to override the `update`, `delete` and `find` methods to use the uuid instead of the id. However after doing that, the deletion breaks because the BaseRepository calls the `find`method of the son instead of the one of itself.

This is the code of the BaseRepository:

```
public function delete($id)
{
$this->applyScope();

$temporarySkipPresenter = $this->skipPresenter;
$this->skipPresenter(true);

$model = $this->find($id); <------ $this is an instance of my Repository instead of BaseRepository
$originalModel = clone $model;

$this->skipPresenter($temporarySkipPresenter);
$this->resetModel();

$deleted = $model->delete();

event(new RepositoryEntityDeleted($this, $originalModel));

return $deleted;
}
```

This is the code of the overridden methods `delete` and `find` in my Repository:

```
public function delete($uuid)
{
$entity = $this->getByUuid($uuid);
parent::delete($entity->id);
}
public function find($uuid, $columns = ['*'])
{
$floor = $this->getByUuid($uuid);
return parent::find($floor->id, $columns);
}
```

The BaseRepository should call the find of itself not from the children. Please could you take a look to this?

Thanks.

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.