Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Admin/UsersController.php
Show All 10 Lines | class UsersController extends \App\Http\Controllers\API\V4\UsersController | ||||
/** | /** | ||||
* Searching of user accounts. | * Searching of user accounts. | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$search = trim(request()->input('search')); | $search = trim(request()->input('search')); | ||||
$owner = trim(request()->input('owner')); | |||||
$result = collect([]); | $result = collect([]); | ||||
if (strpos($search, '@')) { | if ($owner) { | ||||
if ($owner = User::find($owner)) { | |||||
$result = $owner->users(false)->orderBy('email')->get(); | |||||
} | |||||
} elseif (strpos($search, '@')) { | |||||
// Search by email | // Search by email | ||||
if ($user = User::findByEmail($search, false)) { | if ($user = User::findByEmail($search, false)) { | ||||
$result->push($user); | $result->push($user); | ||||
} else { | } else { | ||||
// Search by an external email | // Search by an external email | ||||
// TODO: This is not optimal (external email should be in users table) | // TODO: This is not optimal (external email should be in users table) | ||||
$user_ids = UserSetting::where('key', 'external_email')->where('value', $search) | $user_ids = UserSetting::where('key', 'external_email')->where('value', $search) | ||||
->get()->pluck('user_id'); | ->get()->pluck('user_id'); | ||||
Show All 34 Lines |