Skip to content

Commit dee6aa8

Browse files
committed
Deleting the entity
1 parent 02d6c0d commit dee6aa8

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/Repositories/EloquentRepository.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,12 @@ public function update(int $id, array $fieldsData)
148148
*/
149149
public function delete(array $conditions)
150150
{
151-
$primaryKeyId = $conditions[$this->getBaseModel()->getPrimaryKey()] ?? null;
152-
if (!empty($primaryKeyId)) {
153-
$model = $this->read(
154-
[
155-
$this->getBaseModel()->getPrimaryKey() => $conditions[$this->getBaseModel()->getPrimaryKey()],
156-
]
157-
);
158-
159-
return $model->delete();
151+
$model = $this->read($conditions);
152+
153+
if (!empty($model) && !empty($model->first())) {
154+
return $model->first()->deleteOrFail();
160155
}
161156

162-
return false;
157+
throw new \Exception("Unable to delete, entity not found");
163158
}
164159
}

0 commit comments

Comments
 (0)