Skip to content

Commit 4e20aa8

Browse files
authoredMay 24, 2021
Merge pull request #5 from haipham22/findorcreate
Add method
2 parents ee353d0 + e115779 commit 4e20aa8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎src/Repositories/AbstractRepository.php

+13
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ public function findBy($field, $value, $columns = ['*'])
237237

238238
return $this->query->where($field, '=', $value)->first($columns);
239239
}
240+
241+
/**
242+
* Get the first record matching the attributes or create it.
243+
*
244+
* @param array $attributes
245+
* @param array $values
246+
* @return Model|static
247+
*/
248+
public function findOrCreate(array $attributes = [], array $values = [])
249+
{
250+
$this->newQuery();
251+
return $this->query->firstOrCreate($attributes, $values);
252+
}
240253

241254
/**
242255
* Find data by field

0 commit comments

Comments
 (0)
Please sign in to comment.