Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Reseller/GroupsController.php
Show All 14 Lines | class GroupsController extends \App\Http\Controllers\API\V4\Admin\GroupsController | ||||
public function index() | public function index() | ||||
{ | { | ||||
$search = trim(request()->input('search')); | $search = trim(request()->input('search')); | ||||
$owner = trim(request()->input('owner')); | $owner = trim(request()->input('owner')); | ||||
$result = collect([]); | $result = collect([]); | ||||
if ($owner) { | if ($owner) { | ||||
if ($owner = User::withSubjectTenantContext()->find($owner)) { | if ($owner = User::withSubjectTenantContext()->find($owner)) { | ||||
foreach ($owner->wallets as $wallet) { | $result = $owner->groups(false)->orderBy('name')->get(); | ||||
$wallet->entitlements()->where('entitleable_type', Group::class)->get() | |||||
->each(function ($entitlement) use ($result) { | |||||
$result->push($entitlement->entitleable); | |||||
}); | |||||
} | |||||
$result = $result->sortBy('name')->values(); | |||||
} | } | ||||
} elseif (!empty($search)) { | } elseif (!empty($search)) { | ||||
if ($group = Group::withSubjectTenantContext()->where('email', $search)->first()) { | if ($group = Group::withSubjectTenantContext()->where('email', $search)->first()) { | ||||
$result->push($group); | $result->push($group); | ||||
} | } | ||||
} | } | ||||
// Process the result | // Process the result | ||||
Show All 15 Lines |