andersao / andersao/l5-repository

Overriding the find method

オープン
#286 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
PHP
スター
4.2k
フォーク
880
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

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

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