22-05-2026 Optimierung der User und Admin Panels
This commit is contained in:
parent
d2ba22c0cf
commit
e8c47b7553
73 changed files with 10282 additions and 1546 deletions
|
|
@ -6,7 +6,7 @@ use App\Models\Company;
|
|||
use App\Models\User;
|
||||
use App\Services\Admin\AdminPerformanceCache;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Title;
|
||||
|
|
@ -66,18 +66,8 @@ new #[Layout('components.layouts.app'), Title('Benutzer')] class extends Compone
|
|||
'pressReleases as published_press_releases_count' => fn ($query) => $query->where('status', PressReleaseStatus::Published->value),
|
||||
])
|
||||
->withExists(['profile', 'billingAddress'])
|
||||
->when($this->search, function ($query): void {
|
||||
$term = trim($this->search);
|
||||
|
||||
if ($this->supportsFullTextSearch($term)) {
|
||||
$query->whereFullText(['name', 'email'], $term);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(function ($searchQuery): void {
|
||||
$searchQuery->where('name', 'like', '%'.$this->search.'%')->orWhere('email', 'like', '%'.$this->search.'%');
|
||||
});
|
||||
->when(filled(trim($this->search)), function (Builder $query): void {
|
||||
$this->applySearch($query, $this->search);
|
||||
})
|
||||
->when($this->activeFilter !== 'all', function ($query): void {
|
||||
$query->where('is_active', $this->activeFilter === 'active');
|
||||
|
|
@ -115,7 +105,7 @@ new #[Layout('components.layouts.app'), Title('Benutzer')] class extends Compone
|
|||
};
|
||||
})
|
||||
->orderBy($sort, $this->sortDir)
|
||||
->simplePaginate(50);
|
||||
->paginate(50);
|
||||
|
||||
$this->hydrateCompanyCounts($users);
|
||||
|
||||
|
|
@ -266,9 +256,30 @@ new #[Layout('components.layouts.app'), Title('Benutzer')] class extends Compone
|
|||
->find($this->viewingUserId);
|
||||
}
|
||||
|
||||
private function supportsFullTextSearch(string $term): bool
|
||||
private function applySearch(Builder $query, string $search): void
|
||||
{
|
||||
return mb_strlen($term) >= 3 && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'], true);
|
||||
$terms = preg_split('/\s+/', trim($search), -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
if ($terms === false || $terms === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(function (Builder $searchQuery) use ($terms): void {
|
||||
foreach ($terms as $term) {
|
||||
$pattern = '%'.$this->escapeLikeTerm($term).'%';
|
||||
|
||||
$searchQuery->where(function (Builder $termQuery) use ($pattern): void {
|
||||
$termQuery
|
||||
->whereLike('name', $pattern)
|
||||
->orWhereLike('email', $pattern);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function escapeLikeTerm(string $term): string
|
||||
{
|
||||
return addcslashes($term, '\%_');
|
||||
}
|
||||
|
||||
public function updatedSearch(): void
|
||||
|
|
@ -586,7 +597,7 @@ new #[Layout('components.layouts.app'), Title('Benutzer')] class extends Compone
|
|||
</flux:table>
|
||||
|
||||
<div class="border-t border-[color:var(--color-bg-rule)] p-4">
|
||||
{{ $users->links() }}
|
||||
{{ $users->links('components.portal.pagination') }}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue