Created
April 23, 2018 16:21
-
-
Save sr2ds/77182c42be7385cbddc5eb1c6d99f615 to your computer and use it in GitHub Desktop.
Search Method for Laravel Repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function search($input = []) { | |
$query = $this->model; | |
if (isset($input['tenant_id'])) | |
$query = $query->ofTenantId($input['tenant_id']); | |
if (isset($input['keywords']) && ($k = $input['keywords'])) { | |
$query = $query | |
->where(function ($subquery) use ($k) { | |
return $subquery | |
->where('last_name', 'like', "%{$k}%") | |
->orWhere('first_name', 'like', "%{$k}%") | |
->orWhere('identity', 'like', "%{$k}%") | |
->orWhere('email', 'like', "%{$k}%"); | |
}); | |
} | |
return $query->select('users.*')->orderBy('users.created_at', 'desc'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment