Skip to content

Commit c0da4c1

Browse files
committed
minor fix on find methods and added upserts
1 parent c476e45 commit c0da4c1

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/Contracts/RepositoryInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function paginate($limit = null, $columns = ['*']): mixed;
3131

3232
public function simplePaginate($limit = null, $columns = ['*']): mixed;
3333

34-
public function find(int $id, $columns = ['*']): mixed;
34+
public function find(mixed $id, $columns = ['*']): mixed;
3535

3636
public function findByField(string $field, $value, $columns = ['*']): mixed;
3737

@@ -53,6 +53,8 @@ public function updateWhere(array $where, array $attributes): ?bool;
5353

5454
public function updateOrCreate(array $attributes, array $values = []): mixed;
5555

56+
public function upsert(array $values, array|string $uniqueBy, array|null $update = null): int;
57+
5658
public function delete(int $id): mixed;
5759

5860
public function deleteWhere(array $where): ?bool;

src/Eloquent/BaseRepository.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function simplePaginate($limit = null, $columns = ['*']): mixed
204204
return $this->paginate($limit, $columns, "simplePaginate");
205205
}
206206

207-
public function find(int $id, $columns = ['*']): mixed
207+
public function find(mixed $id, $columns = ['*']): mixed
208208
{
209209
$this->applyCriteria();
210210
$this->applyScope();
@@ -336,6 +336,17 @@ public function updateOrCreate(array $attributes, array $values = []): mixed
336336
return $model;
337337
}
338338

339+
public function upsert(array $values, array|string $uniqueBy, ?array $update = null): int
340+
{
341+
$upserted = $this->model->upsert($values, $uniqueBy, $update);
342+
343+
event(new RepositoryEntityCreated($this, $this->model->getModel()));
344+
345+
$this->resetModel();
346+
347+
return $upserted;
348+
}
349+
339350
public function delete(int $id): mixed
340351
{
341352
return $this->manageDeletes($id, 'delete');

src/Traits/Cacheable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function paginate($limit = null, $columns = ['*'], $method = 'paginate'):
147147
return $value;
148148
}
149149

150-
public function find(int $id, $columns = ['*']): mixed
150+
public function find(mixed $id, $columns = ['*']): mixed
151151
{
152152
if (!$this->allowedCache('find') || $this->isSkippedCache()) {
153153
return parent::find($id, $columns);

0 commit comments

Comments
 (0)