Fix server resources tab 500 error with mixed model types

The Resources tab threw a "Queueing collections with multiple model types is not supported" error because the Livewire component was storing a mixed-type Eloquent collection (Applications, Databases, Services) as a public property, causing Livewire's serialization to fail.

Fixed by: storing only the unmanaged containers array in the component, and calling definedResources() directly in the Blade view for the managed tab.

Fixes #7666

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai 2025-12-17 18:13:55 +01:00
parent 1b3be5bef6
commit 4b65b02103
4 changed files with 61 additions and 26 deletions

View File

@ -4,7 +4,6 @@ namespace App\Livewire\Server;
use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Collection;
use Livewire\Component;
class Resources extends Component
@ -15,7 +14,7 @@ class Resources extends Component
public $parameters = [];
public Collection $containers;
public array $unmanagedContainers = [];
public $activeTab = 'managed';
@ -64,7 +63,7 @@ class Resources extends Component
{
try {
$this->activeTab = 'managed';
$this->containers = $this->server->refresh()->definedResources();
$this->server->refresh();
} catch (\Throwable $e) {
return handleError($e, $this);
}
@ -74,7 +73,7 @@ class Resources extends Component
{
$this->activeTab = 'unmanaged';
try {
$this->containers = $this->server->loadUnmanagedContainers();
$this->unmanagedContainers = $this->server->loadUnmanagedContainers()->toArray();
} catch (\Throwable $e) {
return handleError($e, $this);
}
@ -82,14 +81,12 @@ class Resources extends Component
public function mount()
{
$this->containers = collect();
$this->parameters = get_route_parameters();
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->first();
if (is_null($this->server)) {
return redirect()->route('server.index');
}
$this->loadManagedContainers();
} catch (\Throwable $e) {
return handleError($e, $this);
}

View File

@ -32,8 +32,11 @@
</div>
</div>
</div>
@if ($containers->count() > 0)
@if ($activeTab === 'managed')
@if ($activeTab === 'managed')
@php
$managedResources = $server->definedResources()->sortBy('name', SORT_NATURAL);
@endphp
@if ($managedResources->count() > 0)
<div class="flex flex-col">
<div class="flex flex-col">
<div class="overflow-x-auto">
@ -59,7 +62,7 @@
</tr>
</thead>
<tbody>
@forelse ($server->definedResources()->sortBy('name',SORT_NATURAL) as $resource)
@foreach ($managedResources as $resource)
<tr>
<td class="px-5 py-4 text-sm whitespace-nowrap">
{{ data_get($resource->project(), 'name') }}
@ -83,8 +86,7 @@
@endif
</td>
</tr>
@empty
@endforelse
@endforeach
</tbody>
</table>
</div>
@ -92,7 +94,11 @@
</div>
</div>
</div>
@elseif ($activeTab === 'unmanaged')
@else
<div>No managed resources found.</div>
@endif
@elseif ($activeTab === 'unmanaged')
@if (count($unmanagedContainers) > 0)
<div class="flex flex-col">
<div class="flex flex-col">
<div class="overflow-x-auto">
@ -116,7 +122,7 @@
</tr>
</thead>
<tbody>
@forelse ($containers->sortBy('name',SORT_NATURAL) as $resource)
@foreach (collect($unmanagedContainers)->sortBy('name', SORT_NATURAL) as $resource)
<tr>
<td class="px-5 py-4 text-sm whitespace-nowrap">
{{ data_get($resource, 'Names') }}
@ -146,19 +152,15 @@
@endif
</td>
</tr>
@empty
@endforelse
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
@endif
@else
@if ($activeTab === 'managed')
<div>No managed resources found.</div>
@elseif ($activeTab === 'unmanaged')
</div>
@else
<div>No unmanaged resources found.</div>
@endif
@endif

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long