implement SearchUsers use case
This commit is contained in:
parent
31a807f0ae
commit
d917e76f1b
5 changed files with 93 additions and 0 deletions
|
|
@ -43,6 +43,25 @@ class EloquentUserRepository implements UserRepository
|
|||
return $model === null ? null : $this->toDomain($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function search(string $query): array
|
||||
{
|
||||
$like = strtolower($query).'%';
|
||||
$models = UserModel::query()
|
||||
->whereRaw('LOWER(display_name) LIKE ?', [$like])
|
||||
->orWhereRaw('LOWER(email) LIKE ?', [$like])
|
||||
->orderBy('display_name')
|
||||
->get();
|
||||
|
||||
return $models->map(
|
||||
function (UserModel $model) {
|
||||
return $this->toDomain($model);
|
||||
},
|
||||
)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue