| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- use App\Rules\TinyMCERule;
- use App\Rules\AllowTagString;
- use App\Rules\NormalString;
- use App\Http\Traits\BoardTrait;
- class PostRequest extends FormRequest
- {
- use BoardTrait;
- /**
- * Determine if the user is authorized to make this request.
- *
- * @return bool
- */
- public function authorize()
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules()
- {
- $bid = $this->post('bid');
- $pid = $this->post('pid');
- $boardMeta = $this->boardMeta;
- $rules = [
- 'bid' => 'required|numeric|exists:tb_board,id',
- 'pid' => 'nullable|numeric',
- 'is_speaker' => 'numeric|in:0,1',
- 'is_notice' => 'numeric|in:0,1',
- 'is_secret' => 'numeric|in:0,1',
- 'subject' => ['required', 'string'],
- 'content' => ['required', new TinyMCERule],
- ];
- if($pid) {
- $rules['pid'] = 'required|exists:tb_post,id';
- }
- if(($postSubjectMinLength = $boardMeta->item('post_subject_min_length', 0)) > 0) {
- $rules['subject'][] = "min:$postSubjectMinLength";
- }
- if(($postSubjectMaxLength = $boardMeta->item('post_subject_max_length', 0)) > 0) {
- $rules['subject'][] = "max:$postSubjectMaxLength";
- }
- if(($postContentMinLength = $boardMeta->item('post_content_min_length', 0)) > 0) {
- $rules['content'][] = "min:$postContentMinLength";
- }
- if(($postContentMaxLength = $boardMeta->item('post_content_max_length', 0)) > 0) {
- $rules['content'][] = "max:$postContentMaxLength";
- }
- // 자동등록방지문자 확인
- if($boardMeta->item('use_post_captcha', 0)) {
- $rules['captcha'] = 'required|valid_captcha';
- }
- // 분류
- if($boardMeta->item('use_category', 0))
- {
- $rules['category'][] = 'exists:tb_board_category,id';
- // 분류 필수값 선택 사용시
- $rules['category'][] = ($boardMeta->item('use_category_required', 0) ? 'required' : 'nullable');
- }
- // Tag
- if($boardMeta->item('use_post_tag', 0)) {
- $rules['tags'] = new AllowTagString;
- }
- // Link
- if($boardMeta->item('link_num', 0) > 0) {
- $rules['links.*'] = 'nullable|url';
- }
- // 파일
- if($boardMeta->item('use_upload_file', 0)) {
- if(($uploadFileMaxSize = $boardMeta->item('upload_file_max_size', 0)) > 0) {
- $rules['files.*'] = 'file|max:' . ($uploadFileMaxSize * 1024 * 1024);
- }
- }
- // 비회원 유효성 검사
- if(!$this->user()) {
- $rules['username'] = ['required', 'min:2', 'max:10', 'string', new NormalString];
- $rules['password'] = 'required|min:3|max:10';
- }
- return $rules;
- }
- /**
- * Get custom attributes for validator errors.
- *
- * @return array
- */
- public function attributes()
- {
- return [
- 'bid' => '게시판 PK',
- 'pid' => '게시글 PK',
- 'is_speaker' => '전체공지',
- 'is_notice' => '공지사항',
- 'is_secret' => '비밀글',
- 'username' => '이름',
- 'password' => '비밀번호',
- 'category' => '분류',
- 'subject' => '제목',
- 'content' => '내용',
- 'tag' => 'Tag',
- 'link.*' => 'Link',
- 'file.*' => 'File',
- 'captcha' => '자동등록방지문자'
- ];
- }
- /**
- * Get the error messages for the defined validation rules.
- *
- * @return array
- */
- public function messages()
- {
- return [
- 'username.required' => '이름을 입력하세요.',
- 'username.min' => '이름은 :min자 이상 입력하세요.',
- 'username.max' => '이름은 :max자 이하 입력하세요.',
- 'username.string' => '이름 형식이 옳지 않습니다.',
- 'password.required' => '비밀번호를 입력하세요.',
- 'password.min' => '비밀번호는 :min자 이상 입력하세요.',
- 'password.max' => '비밀번호는 :max자 이하 입력하세요.',
- 'category.required' => '분류를 선택하세요.',
- 'subject.required' => '제목을 입력하세요.',
- 'content.required' => '내용을 입력하세요.',
- 'link.required' => '`Link`를 입력하세요.',
- 'link.url' => '`Link`형식이 옳지 않습니다.',
- 'file.required' => '`File`를 첨부하세요.',
- 'file.file' => '`File`형식이 옳지 않습니다.',
- 'file.*.size' => '첨부 가능한 파일의 최대 크기는 :sizeMB 입니다.',
- 'captcha.required' => '자동등록방지 문자를 입력하세요.',
- 'captcha.valid_captcha' => '자동등록방지 문자 유효성 검사에 실패했습니다. 다시 시도해 주세요.'
- ];
- }
- }
|