mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 13:32:43 +01:00
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\V1\Project;
|
|
|
|
use App\Models\Client;
|
|
use App\Models\Organization;
|
|
use App\Rules\ColorRule;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
|
|
|
/**
|
|
* @property Organization $organization Organization from model binding
|
|
*/
|
|
class ProjectStoreRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, array<string|ValidationRule>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => [
|
|
// TODO: unique
|
|
'required',
|
|
'string',
|
|
'min:1',
|
|
'max:255',
|
|
],
|
|
'color' => [
|
|
'required',
|
|
'string',
|
|
'max:255',
|
|
new ColorRule(),
|
|
],
|
|
'client_id' => [
|
|
'nullable',
|
|
new ExistsEloquent(Client::class, null, function (Builder $builder): Builder {
|
|
/** @var Builder<Client> $builder */
|
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
|
}),
|
|
],
|
|
];
|
|
}
|
|
}
|