andersao / andersao/l5-repository

Overriding the find method

Aperta
#286 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
PHP
Stelle
4.2k
Fork
880
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.