coolify/app/Livewire/Project/AddEmpty.php

41 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project;
use App\Models\Project;
use Livewire\Attributes\Validate;
use Livewire\Component;
2024-11-22 15:03:20 +00:00
use Visus\Cuid2\Cuid2;
class AddEmpty extends Component
{
#[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
#[Validate(['nullable', 'string'])]
public string $description = '';
2024-06-10 20:43:34 +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.',
];
public function submit()
{
try {
$this->validate();
$project = Project::create([
'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,
]);
2024-06-10 20:43:34 +00:00
2023-12-27 15:45:01 +00:00
return redirect()->route('project.show', $project->uuid);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
}