Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Refactor BaseComponent to remove unused code and initialize route parameters in the boot method

Andras Bacsai513c74a7e31b
diff --git a/app/Livewire/BaseComponent.php b/app/Livewire/BaseComponent.php
deleted file mode 100644
index ee9fa238f1..0000000000
--- a/app/Livewire/BaseComponent.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-namespace App\Livewire;
-
-use Livewire\Component;
-
-abstract class BaseComponent extends Component
-{
- public $parameters = [];
-
- public function boot()
- {
- $this->parameters = $this->getRouteParameters();
- }
-
- protected function getRouteParameters()
- {
- return get_route_parameters();
- }
-}
diff --git a/app/Livewire/Project/DeleteEnvironment.php b/app/Livewire/Project/DeleteEnvironment.php
index e01741770a..6d8c3aff79 100644
--- a/app/Livewire/Project/DeleteEnvironment.php
+++ b/app/Livewire/Project/DeleteEnvironment.php
@@ -7,18 +7,22 @@ use Livewire\Component;
class DeleteEnvironment extends Component
{
- public array $parameters;
-
public int $environment_id;
public bool $disabled = false;
public string $environmentName = '';
+ public array $parameters;
+
public function mount()
{
- $this->parameters = get_route_parameters();
- $this->environmentName = Environment::findOrFail($this->environment_id)->name;
+ try {
+ $this->environmentName = Environment::findOrFail($this->environment_id)->name;
+ $this->parameters = get_route_parameters();
+ } catch (\Exception $e) {
+ return handleError($e, $this);
+ }
}
public function delete()
@@ -30,7 +34,7 @@ class DeleteEnvironment extends Component
if ($environment->isEmpty()) {
$environment->delete();
- return redirect()->route('project.show', ['project_uuid' => $this->parameters['project_uuid']]);
+ return redirect()->route('project.show', parameters: ['project_uuid' => $this->parameters['project_uuid']]);
}
return $this->dispatch('error', 'Environment has defined resources, please delete them first.');
diff --git a/app/Livewire/Server/Show.php b/app/Livewire/Server/Show.php
index 0e07ec0a10..85c5f95f85 100644
--- a/app/Livewire/Server/Show.php
+++ b/app/Livewire/Server/Show.php
@@ -2,22 +2,25 @@
namespace App\Livewire\Server;
-use App\Livewire\BaseComponent;
use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Livewire\Component;
-class Show extends BaseComponent
+class Show extends Component
{
use AuthorizesRequests;
public Server $server;
+ public array $parameters;
+
protected $listeners = ['refreshServerShow'];
public function mount()
{
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail();
+ $this->parameters = get_route_parameters();
} catch (\Throwable $e) {
return handleError($e, $this);
}