Fix null pointer exception in Index.php

This commit is contained in:
Andras Bacsai
2024-04-08 11:16:20 +02:00
parent 34aa4c6412
commit 2c41b5d4fb

View File

@@ -10,7 +10,7 @@ use Livewire\Component;
class Index extends Component class Index extends Component
{ {
public Service $service; public ?Service $service = null;
public ?ServiceApplication $serviceApplication = null; public ?ServiceApplication $serviceApplication = null;
public ?ServiceDatabase $serviceDatabase = null; public ?ServiceDatabase $serviceDatabase = null;
public array $parameters; public array $parameters;
@@ -26,7 +26,10 @@ class Index extends Component
$this->services = collect([]); $this->services = collect([]);
$this->parameters = get_route_parameters(); $this->parameters = get_route_parameters();
$this->query = request()->query(); $this->query = request()->query();
$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail(); $this->service = Service::whereUuid($this->parameters['service_uuid'])->first();
if (!$this->service) {
return redirect()->route('dashboard');
}
$service = $this->service->applications()->whereUuid($this->parameters['stack_service_uuid'])->first(); $service = $this->service->applications()->whereUuid($this->parameters['stack_service_uuid'])->first();
if ($service) { if ($service) {
$this->serviceApplication = $service; $this->serviceApplication = $service;