mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-05-07 20:32:26 +00:00
49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\V1\Task;
|
|
|
|
use App\Models\Organization;
|
|
use App\Models\Project;
|
|
use App\Models\Task;
|
|
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
|
|
*/
|
|
class TaskStoreRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, array<string|ValidationRule>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'min:1',
|
|
'max:255',
|
|
(new UniqueEloquent(Task::class, 'name', function (Builder $builder): Builder {
|
|
/** @var Builder<Task> $builder */
|
|
return $builder->where('project_id', '=', $this->input('project_id'));
|
|
}))->withCustomTranslation('validation.task_name_already_exists'),
|
|
],
|
|
'project_id' => [
|
|
'required',
|
|
new ExistsEloquent(Project::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Project> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
|
}),
|
|
],
|
|
];
|
|
}
|
|
}
|