Skip to content

Instantly share code, notes, and snippets.

@rogercbe
Created October 18, 2018 12:18
Show Gist options
  • Select an option

  • Save rogercbe/a32b75c00794f90ab336cf6eb09b8ecf to your computer and use it in GitHub Desktop.

Select an option

Save rogercbe/a32b75c00794f90ab336cf6eb09b8ecf to your computer and use it in GitHub Desktop.
<?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