Make name fields in projects, tasks, clients and tags unique; fixes ST-265

This commit is contained in:
Constantin Graf
2024-06-19 16:01:50 +02:00
committed by Gregor Vostrak
parent 313cee2db0
commit 512089ccbd
21 changed files with 602 additions and 90 deletions

View File

@@ -6,14 +6,17 @@ namespace App\Http\Requests\V1\Project;
use App\Models\Client;
use App\Models\Organization;
use App\Models\Project;
use App\Rules\ColorRule;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Http\FormRequest;
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
use Korridor\LaravelModelValidationRules\Rules\UniqueEloquent;
/**
* @property Organization $organization Organization from model binding
* @property Project $project Project from model binding
*/
class ProjectUpdateRequest extends FormRequest
{
@@ -26,10 +29,13 @@ class ProjectUpdateRequest extends FormRequest
{
return [
'name' => [
// TODO: unique
'required',
'string',
'max:255',
(new UniqueEloquent(Project::class, 'name', function (Builder $builder): Builder {
/** @var Builder<Project> $builder */
return $builder->whereBelongsTo($this->organization, 'organization');
}))->ignore($this->project->getKey())->withCustomTranslation('validation.project_name_already_exists'),
],
'color' => [
'required',