Skip to content

Commit 424fb42

Browse files
committed
[Update] Added firstWhere() method
1 parent 131dac4 commit 424fb42

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Contracts/RepositoryInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function get($columns = ['*']): mixed;
2121

2222
public function first($columns = ['*']): mixed;
2323

24+
public function firstWhere(array $where, $columns = ['*']): mixed;
25+
2426
public function firstOrNew(array $attributes, array $values = []): mixed;
2527

2628
public function firstOrCreate(array $attributes, array $values = []): mixed;

src/Eloquent/BaseRepository.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ public function first($columns = ['*']): mixed
152152
return $result;
153153
}
154154

155+
public function firstWhere(array $where, $columns = ['*']): mixed
156+
{
157+
$this->applyCriteria();
158+
$this->applyScope();
159+
160+
$this->applyConditions($where);
161+
162+
$result = $this->model->first($columns);
163+
164+
$this->resetModel();
165+
166+
return $result;
167+
}
168+
155169
public function firstOrNew(array $attributes, array $values = []): mixed
156170
{
157171
$this->applyCriteria();

0 commit comments

Comments
 (0)