coolify/app/Livewire/Project/Edit.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2023-06-22 07:33:26 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project;
2023-06-22 07:33:26 +00:00
use App\Models\Project;
use Livewire\Attributes\Validate;
2023-06-22 07:33:26 +00:00
use Livewire\Component;
class Edit extends Component
{
public Project $project;
2024-06-10 20:43:34 +00:00
#[Validate(['required', 'string', 'min:3', 'max:255'])]
2024-11-03 22:55:04 +00:00
public string $name;
2024-06-10 20:43:34 +00:00
#[Validate(['nullable', 'string', 'max:255'])]
2024-11-03 22:55:04 +00:00
public ?string $description = null;
public function mount(string $project_uuid)
{
try {
$this->project = Project::where('team_id', currentTeam()->id)->where('uuid', $project_uuid)->firstOrFail();
$this->syncData();
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function syncData(bool $toModel = false)
2024-01-23 16:13:23 +00:00
{
2024-11-03 22:55:04 +00:00
if ($toModel) {
$this->validate();
$this->project->update([
'name' => $this->name,
'description' => $this->description,
]);
} else {
$this->name = $this->project->name;
$this->description = $this->project->description;
2024-01-07 15:23:41 +00:00
}
}
2023-06-22 13:25:57 +00:00
2023-06-22 07:33:26 +00:00
public function submit()
{
try {
2024-11-03 22:55:04 +00:00
$this->syncData(true);
2024-03-21 13:30:35 +00:00
$this->dispatch('success', 'Project updated.');
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-06-22 07:33:26 +00:00
}
}
}