Skip to content

Commit 0a9eea2

Browse files
author
Roman Dubrovin
committed
Merge branch 'dpankratov/find-findby-methods' into 'master'
added find/findBy methods See merge request components/laravel-helpers!41
2 parents c4207b1 + 4ab2596 commit 0a9eea2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Traits/EntityControlTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ public function firstWithRelations($data, $with = [])
131131
return empty($entity) ? [] : $entity->toArray();
132132
}
133133

134+
public function findBy($field, $value, $relations = [])
135+
{
136+
return $this->firstWithRelations([
137+
$field => $value
138+
], $relations);
139+
}
140+
141+
public function find($id, $relations = [])
142+
{
143+
return $this->firstWithRelations([
144+
'id' => $id
145+
], $relations);
146+
}
147+
134148
public function delete($where)
135149
{
136150
$model = new $this->model;

0 commit comments

Comments
 (0)