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

View file

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long