dispatch('$refresh'); } public function openAliasCreate(int $domainId): void { $this->dispatch('openModal', component: 'ui.mail.modal.alias-form-modal', arguments: [ 'domainId' => $domainId, ]); } public function openAliasEdit(int $aliasId): void { $this->dispatch('openModal', component: 'ui.mail.modal.alias-form-modal', arguments: [ 'aliasId' => $aliasId, ]); } public function openAliasDelete(int $aliasId): void { $this->dispatch('openModal', component: 'ui.mail.modal.alias-delete-modal', arguments: [ 'aliasId' => $aliasId, ]); } public function render() { $term = trim($this->search); $hasTerm = $term !== ''; $needle = '%' . str_replace(['%', '_'], ['\%', '\_'], $term) . '%'; $domains = Domain::query() ->where('is_system', false) ->where('is_server', false) ->when($hasTerm, function ($q) use ($needle) { $q->where(function ($w) use ($needle) { $w->where('domain', 'like', $needle) ->orWhereHas('mailAliases', fn($a) => $a ->where('is_system', false) ->where(fn($x) => $x ->where('local', 'like', $needle) ->orWhere('destination', 'like', $needle) ) ); }); }) ->withCount(['mailAliases as aliases_count' => fn($a) => $a->where('is_system', false)]) ->with(['mailAliases' => function ($q) use ($hasTerm, $needle) { $q->where('is_system', false); if ($hasTerm) { $q->where(fn($x) => $x ->where('local', 'like', $needle) ->orWhere('destination', 'like', $needle) ); } $q->orderBy('local'); }]) ->orderBy('domain') ->get(); if ($hasTerm) { $lower = Str::lower($term); foreach ($domains as $d) { if (Str::contains(Str::lower($d->domain), $lower)) { $d->setRelation('mailAliases', $d->mailAliases() ->where('is_system', false) ->orderBy('local') ->get() ); } } } $totalAliases = $domains->sum('aliases_count'); return view('livewire.ui.nx.mail.alias-list', [ 'domains' => $domains, 'totalAliases' => $totalAliases, ]); } }