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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor project env edit livewire
Andras Bacsaica7290cebed5
diff --git a/app/Livewire/Project/EnvironmentEdit.php b/app/Livewire/Project/EnvironmentEdit.phpindex 16fc7bc36b..fc33cf6b6d 100644--- a/app/Livewire/Project/EnvironmentEdit.php+++ b/app/Livewire/Project/EnvironmentEdit.php@@ -4,6 +4,8 @@ namespace App\Livewire\Project;use App\Models\Application;use App\Models\Project;+use Livewire\Attributes\Locked;+use Livewire\Attributes\Rule;use Livewire\Component;class EnvironmentEdit extends Component@@ -12,29 +14,45 @@ class EnvironmentEdit extends Componentpublic Application $application;+ #[Locked]public $environment;- public array $parameters;+ #[Rule(['required', 'string', 'min:3', 'max:255'])]+ public string $name;- protected $rules = [- 'environment.name' => 'required|min:3|max:255',- 'environment.description' => 'nullable|min:3|max:255',- ];+ #[Rule(['nullable', 'string', 'max:255'])]+ public ?string $description = null;- public function mount()+ public function mount(string $project_uuid, string $environment_name){- $this->parameters = get_route_parameters();- $this->project = Project::ownedByCurrentTeam()->where('uuid', request()->route('project_uuid'))->first();- $this->environment = $this->project->environments()->where('name', request()->route('environment_name'))->first();+ try {+ $this->project = Project::ownedByCurrentTeam()->where('uuid', $project_uuid)->firstOrFail();+ $this->environment = $this->project->environments()->where('name', $environment_name)->firstOrFail();+ $this->syncData();+ } catch (\Throwable $e) {+ return handleError($e, $this);+ }+ }++ public function syncData(bool $toModel = false)+ {+ if ($toModel) {+ $this->validate();+ $this->environment->update([+ 'name' => $this->name,+ 'description' => $this->description,+ ]);+ } else {+ $this->name = $this->environment->name;+ $this->description = $this->environment->description;+ }}public function submit(){- $this->validate();try {- $this->environment->save();-- return redirect()->route('project.environment.edit', ['project_uuid' => $this->project->uuid, 'environment_name' => $this->environment->name]);+ $this->syncData(true);+ $this->redirectRoute('project.environment.edit', ['environment_name' => $this->environment->name, 'project_uuid' => $this->project->uuid]);} catch (\Throwable $e) {return handleError($e, $this);}diff --git a/resources/views/livewire/project/environment-edit.blade.php b/resources/views/livewire/project/environment-edit.blade.phpindex 2035259595..af5e686c48 100644--- a/resources/views/livewire/project/environment-edit.blade.php+++ b/resources/views/livewire/project/environment-edit.blade.php@@ -13,7 +13,7 @@<li class="inline-flex items-center"><div class="flex items-center"><a class="text-xs truncate lg:text-sm"- href="{{ route('project.show', ['project_uuid' => data_get($parameters, 'project_uuid')]) }}">+ href="{{ route('project.show', ['project_uuid' => $project->uuid]) }}">{{ $project->name }}</a><svg aria-hidden="true" class="w-4 h-4 mx-1 font-bold dark:text-warning" fill="currentColor"viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">@@ -26,7 +26,9 @@<li><div class="flex items-center"><a class="text-xs truncate lg:text-sm"- href="{{ route('project.resource.index', ['environment_name' => data_get($parameters, 'environment_name'), 'project_uuid' => data_get($parameters, 'project_uuid')]) }}">{{ data_get($parameters, 'environment_name') }}</a>+ href="{{ route('project.resource.index', ['environment_name' => $environment->name, 'project_uuid' => $project->uuid]) }}">+ {{ $environment->name }}+ </a></div></li><li>@@ -43,8 +45,8 @@</ol></nav><div class="flex gap-2">- <x-forms.input label="Name" id="environment.name" />- <x-forms.input label="Description" id="environment.description" />+ <x-forms.input label="Name" id="name" />+ <x-forms.input label="Description" id="description" /></div></form></div>