Created
October 18, 2018 12:18
-
-
Save rogercbe/a32b75c00794f90ab336cf6eb09b8ecf to your computer and use it in GitHub Desktop.
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
| <?php | |
| class GlobalSearch | |
| { | |
| protected $searchGroups = [ | |
| 'Users' => UserSearchGroup::class, | |
| ]; | |
| protected function searchGroups() | |
| { | |
| return collect($this->searchGroups); | |
| } | |
| public function search($value) | |
| { | |
| return $this->searchGroups()->map(function ($group) { | |
| $group->search($value); | |
| }); | |
| } | |
| } | |
| abstract class SearchGroup | |
| { | |
| abstract public function search($value); | |
| } | |
| class UserSearchGroup extends SearchGroup | |
| { | |
| public function search($value) | |
| { | |
| return User::where('name', 'like', $value)->get(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment