coolify/app/Livewire/Project/Edit.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2023-06-22 09:33:26 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire\Project;
2023-06-22 09:33:26 +02:00
use App\Models\Project;
use Livewire\Component;
class Edit extends Component
{
public Project $project;
protected $rules = [
'project.name' => 'required|min:3|max:255',
'project.description' => 'nullable|string|max:255',
];
2024-01-23 17:13:23 +01:00
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];
public function saveKey($data)
{
try {
$this->project->environment_variables()->create([
'key' => $data['key'],
'value' => $data['value'],
'type' => 'project',
'team_id' => currentTeam()->id,
]);
$this->project->refresh();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function mount()
{
2024-01-07 16:23:41 +01:00
$projectUuid = request()->route('project_uuid');
$teamId = currentTeam()->id;
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
if (!$project) {
return redirect()->route('dashboard');
}
$this->project = $project;
}
2023-06-22 15:25:57 +02:00
2023-06-22 09:33:26 +02:00
public function submit()
{
$this->validate();
try {
$this->project->save();
2023-12-07 19:06:32 +01:00
$this->dispatch('saved');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-06-22 09:33:26 +02:00
}
}
}