2023-07-26 11:23:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project;
|
2023-07-26 11:23:47 +00:00
|
|
|
|
|
|
|
|
use App\Models\Project;
|
2025-08-19 10:14:48 +00:00
|
|
|
use App\Support\ValidationPatterns;
|
2023-07-26 11:23:47 +00:00
|
|
|
use Livewire\Component;
|
2024-11-22 15:03:20 +00:00
|
|
|
use Visus\Cuid2\Cuid2;
|
2023-07-26 11:23:47 +00:00
|
|
|
|
|
|
|
|
class AddEmpty extends Component
|
|
|
|
|
{
|
2024-11-03 22:42:00 +00:00
|
|
|
public string $name;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-07-26 11:23:47 +00:00
|
|
|
public string $description = '';
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-08-19 10:14:48 +00:00
|
|
|
protected function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'name' => ValidationPatterns::nameRules(),
|
|
|
|
|
'description' => ValidationPatterns::descriptionRules(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function messages(): array
|
|
|
|
|
{
|
|
|
|
|
return ValidationPatterns::combinedMessages();
|
|
|
|
|
}
|
2025-08-19 09:04:23 +00:00
|
|
|
|
2023-07-26 11:23:47 +00:00
|
|
|
public function submit()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$this->validate();
|
2025-01-07 14:31:43 +00:00
|
|
|
$project = Project::create([
|
2023-07-26 11:23:47 +00:00
|
|
|
'name' => $this->name,
|
|
|
|
|
'description' => $this->description,
|
2023-08-22 15:44:49 +00:00
|
|
|
'team_id' => currentTeam()->id,
|
2024-11-22 15:03:20 +00:00
|
|
|
'uuid' => (string) new Cuid2,
|
2023-07-26 11:23:47 +00:00
|
|
|
]);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-12-27 15:45:01 +00:00
|
|
|
return redirect()->route('project.show', $project->uuid);
|
2025-01-07 14:31:43 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-07-26 11:23:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|