clusev/app/Livewire/Concerns/WithFleetContext.php

28 lines
632 B
PHP

<?php
namespace App\Livewire\Concerns;
use App\Models\Server;
use Illuminate\Support\Collection;
/**
* Shared fleet context for pages: the active server (from session, default
* first) plus the whole fleet. Real metrics come from the SSH layer later.
*/
trait WithFleetContext
{
public function fleet(): Collection
{
return Server::orderBy('name')->get();
}
public function activeServer(): ?Server
{
$fleet = $this->fleet();
return $fleet->firstWhere('id', session('active_server_id'))
?? $fleet->firstWhere('status', 'online')
?? $fleet->first();
}
}