46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Servers;
|
|
|
|
use App\Models\Server;
|
|
use Illuminate\Contracts\View\View;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
#[Title('Server — Clusev')]
|
|
class Index extends Component
|
|
{
|
|
/** Live search over name / IP. */
|
|
public string $search = '';
|
|
|
|
public function render(): View
|
|
{
|
|
$term = trim($this->search);
|
|
|
|
$servers = Server::orderBy('name')
|
|
->when($term !== '', function ($query) use ($term) {
|
|
$query->where(function ($q) use ($term) {
|
|
$q->where('name', 'like', "%{$term}%")
|
|
->orWhere('ip', 'like', "%{$term}%");
|
|
});
|
|
})
|
|
->get();
|
|
|
|
// Totals reflect the whole fleet, not the filtered result.
|
|
$counts = Server::query()
|
|
->selectRaw('status, count(*) as total')
|
|
->groupBy('status')
|
|
->pluck('total', 'status');
|
|
|
|
return view('livewire.servers.index', [
|
|
'servers' => $servers,
|
|
'total' => (int) $counts->sum(),
|
|
'online' => (int) ($counts['online'] ?? 0),
|
|
'warning' => (int) ($counts['warning'] ?? 0),
|
|
'offline' => (int) ($counts['offline'] ?? 0),
|
|
]);
|
|
}
|
|
}
|