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 project edit livewire

Andras Bacsai2f0f244382c6
diff --git a/app/Livewire/Project/Edit.php b/app/Livewire/Project/Edit.php
index bebec4752f..62c1bfc110 100644
--- a/app/Livewire/Project/Edit.php
+++ b/app/Livewire/Project/Edit.php
@@ -3,34 +3,47 @@
namespace App\Livewire\Project;
use App\Models\Project;
+use Livewire\Attributes\Rule;
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',
- ];
+ #[Rule(['required', 'string', 'min:3', 'max:255'])]
+ public string $name;
- public function mount()
+ #[Rule(['nullable', 'string', 'max:255'])]
+ 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)
{
- $projectUuid = request()->route('project_uuid');
- $teamId = currentTeam()->id;
- $project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
- if (! $project) {
- return redirect()->route('dashboard');
+ if ($toModel) {
+ $this->validate();
+ $this->project->update([
+ 'name' => $this->name,
+ 'description' => $this->description,
+ ]);
+ } else {
+ $this->name = $this->project->name;
+ $this->description = $this->project->description;
}
- $this->project = $project;
}
public function submit()
{
try {
- $this->validate();
- $this->project->save();
- $this->dispatch('saved');
+ $this->syncData(true);
$this->dispatch('success', 'Project updated.');
} catch (\Throwable $e) {
return handleError($e, $this);
diff --git a/resources/views/livewire/project/edit.blade.php b/resources/views/livewire/project/edit.blade.php
index ec9304da99..e2f050f4db 100644
--- a/resources/views/livewire/project/edit.blade.php
+++ b/resources/views/livewire/project/edit.blade.php
@@ -11,10 +11,9 @@
</div>
</div>
<div class="pt-2 pb-10">Edit project details here.</div>
-
<div class="flex gap-2">
- <x-forms.input label="Name" id="project.name" />
- <x-forms.input label="Description" id="project.description" />
+ <x-forms.input label="Name" id="name" />
+ <x-forms.input label="Description" id="description" />
</div>
</form>
</div>