Skip to content

Commit 16bdace

Browse files
committed
added few more methods
1 parent 29c60f4 commit 16bdace

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Contracts/RepositoryInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ public function findWhereBetween($field, array $values, $columns = ['*']): mixed
4545

4646
public function create(array $attributes, bool $withoutEvents = false): mixed;
4747

48+
public function insert(array $attributes): ?bool;
49+
4850
public function update(array $attributes, int $id, bool $withoutEvents = false): mixed;
4951

52+
public function updateWhere(array $where, array $attributes): ?bool;
53+
5054
public function updateOrCreate(array $attributes, array $values = []): mixed;
5155

5256
public function delete(int $id): mixed;

src/Eloquent/BaseRepository.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ public function create(array $attributes, bool $withoutEvents = false): mixed
280280
return $model;
281281
}
282282

283+
public function insert(array $attributes): ?bool
284+
{
285+
$inserted = $this->model->insert($attributes);
286+
287+
event(new RepositoryEntityCreated($this, $this->model->getModel()));
288+
289+
$this->resetModel();
290+
291+
return $inserted;
292+
}
293+
283294
public function update(array $attributes, int $id, bool $withoutEvents = false): mixed
284295
{
285296
$this->applyScope();
@@ -298,6 +309,20 @@ public function update(array $attributes, int $id, bool $withoutEvents = false):
298309
return $model;
299310
}
300311

312+
public function updateWhere(array $where, array $attributes): ?bool
313+
{
314+
$this->applyScope();
315+
$this->applyConditions($where);
316+
317+
$updated = $this->model->update($attributes);
318+
319+
event(new RepositoryEntityUpdated($this, $this->model->getModel()));
320+
321+
$this->resetModel();
322+
323+
return $updated;
324+
}
325+
301326
public function updateOrCreate(array $attributes, array $values = []): mixed
302327
{
303328
$this->applyScope();

0 commit comments

Comments
 (0)