From 4ab2596023e038bc8f02d26013d76ab4686fd832 Mon Sep 17 00:00:00 2001 From: Pankratov Denis Date: Thu, 10 May 2018 13:04:45 +0600 Subject: [PATCH] added find/findBy methods --- src/Traits/EntityControlTrait.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Traits/EntityControlTrait.php b/src/Traits/EntityControlTrait.php index 798170d7..be9ced72 100644 --- a/src/Traits/EntityControlTrait.php +++ b/src/Traits/EntityControlTrait.php @@ -131,6 +131,20 @@ public function firstWithRelations($data, $with = []) return empty($entity) ? [] : $entity->toArray(); } + public function findBy($field, $value, $relations = []) + { + return $this->firstWithRelations([ + $field => $value + ], $relations); + } + + public function find($id, $relations = []) + { + return $this->firstWithRelations([ + 'id' => $id + ], $relations); + } + public function delete($where) { $model = new $this->model;