73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\ProjectManagement;
|
||
|
|
|
||
|
|
use App\Models\Admin\AdminPmProject;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
class StoreProjectRequest extends FormRequest
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user is authorized to make this request.
|
||
|
|
*/
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'name' => 'required|string|max:100',
|
||
|
|
'description' => 'nullable|string|max:2000',
|
||
|
|
'status' => 'nullable|in:'.implode(',', array_keys(AdminPmProject::getStatuses())),
|
||
|
|
'start_date' => 'nullable|date',
|
||
|
|
'end_date' => 'nullable|date|after_or_equal:start_date',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get custom attributes for validator errors.
|
||
|
|
*/
|
||
|
|
public function attributes(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'name' => '프로젝트 이름',
|
||
|
|
'description' => '설명',
|
||
|
|
'status' => '상태',
|
||
|
|
'start_date' => '시작일',
|
||
|
|
'end_date' => '종료일',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the error messages for the defined validation rules.
|
||
|
|
*/
|
||
|
|
public function messages(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'name.required' => '프로젝트 이름은 필수입니다.',
|
||
|
|
'name.max' => '프로젝트 이름은 최대 100자까지 입력 가능합니다.',
|
||
|
|
'description.max' => '설명은 최대 2000자까지 입력 가능합니다.',
|
||
|
|
'status.in' => '올바른 상태를 선택해주세요.',
|
||
|
|
'start_date.date' => '올바른 날짜 형식이 아닙니다.',
|
||
|
|
'end_date.date' => '올바른 날짜 형식이 아닙니다.',
|
||
|
|
'end_date.after_or_equal' => '종료일은 시작일 이후여야 합니다.',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Prepare the data for validation.
|
||
|
|
*/
|
||
|
|
protected function prepareForValidation(): void
|
||
|
|
{
|
||
|
|
// 기본값 설정
|
||
|
|
if (! $this->has('status')) {
|
||
|
|
$this->merge(['status' => AdminPmProject::STATUS_ACTIVE]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|