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;
|
2024-11-05 08:36:40 +00:00
|
|
|
use Livewire\Attributes\Validate;
|
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
|
|
|
|
|
{
|
2025-08-19 09:04:23 +00:00
|
|
|
#[Validate(['required', 'string', 'min:3', 'max:255', 'regex:/^[a-zA-Z0-9\s\-_.]+$/'])]
|
2024-11-03 22:42:00 +00:00
|
|
|
public string $name;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-05 08:36:40 +00:00
|
|
|
#[Validate(['nullable', 'string'])]
|
2023-07-26 11:23:47 +00:00
|
|
|
public string $description = '';
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-08-19 09:04:23 +00:00
|
|
|
protected $messages = [
|
|
|
|
|
'name.regex' => 'The name may only contain letters, numbers, spaces, dashes, underscores, and dots.',
|
|
|
|
|
'name.min' => 'The name must be at least 3 characters.',
|
|
|
|
|
'name.max' => 'The name may not be greater than 255 characters.',
|
|
|
|
|
];
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|