| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- use App\Http\Traits\PagingTrait;
- class BoardRequest extends FormRequest
- {
- use PagingTrait;
- /**
- * 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()
- {
- $rules = [
- 'category' => 'nullable|exists:tb_board_category,category_id',
- 'field' => 'nullable|string|in:1,2,3,4,5',
- 'keyword' => 'nullable|string|max:255',
- 'page' => 'nullable|numeric',
- 'perPage' => 'nullable|numeric|in:10,15,20,30,40,50',
- 'sort' => 'nullable|numeric|in:1,2,3,4'
- ];
- $code = $this->route('code');
- $field = $this->query('field'); // 검색구분
- $keyword = $this->query('keyword'); // 검색어
- $page = $this->query('page', 1); // 페이지 번호
- $category = $this->query('category'); // 분류 번호
- // 게시글 설정 값
- $boardMeta = $this->boardMeta;
- // PC/MO 구분 한 페이지당 목록 수
- if(DEVICE_TYPE_1) {
- $perPage = ($this->query('per_page') ?? $boardMeta->list_per_page);
- $pageCount = $boardMeta->list_page_count;
- }else{
- $perPage = ($this->query('per_page') ?? $boardMeta->list_mobile_per_page);
- $pageCount = $boardMeta->list_page_mobile_count;
- }
- $sort = ($this->query('sort') ?? $boardMeta->list_sort_type); // 정렬 (날짜순, 조회순, 댓글순, 추천순)
- $path = route('board.list', $code);
- $offset = $this->getPageOffset($page, $perPage); // 페이징 시작 번호
- $this->merge([
- // 검색 변수
- 'category' => $category,
- 'field' => $field,
- 'keyword' => $keyword,
- 'page' => intval($page),
- 'perPage' => intval($perPage),
- 'pageCount' => intval($pageCount),
- 'offset' => $offset,
- 'sort' => intval($sort),
- 'path' => $path
- ]);
- return $rules;
- }
- /**
- * Get custom attributes for validator errors.
- *
- * @return array
- */
- public function attributes()
- {
- return [
- 'category' => '게시판 종류',
- 'field' => '검색 조건',
- 'keyword' => '검색어',
- 'page' => '목록 번호',
- 'perPage' => '목록 수',
- 'sort' => '정렬 순서'
- ];
- }
- /**
- * Get the error messages for the defined validation rules.
- *
- * @return array
- */
- public function messages()
- {
- return [
- 'category.exists' => '게시판이 존재하지 않습니다.',
- 'field.in' => '검색 조건이 유효하지 않습니다..',
- 'keyword.max' => '검색어는 최대 255글자 입력 가능합니다.',
- 'page.numeric' => '목록 번호가 유효하지 않습니다.',
- 'perPage.in' => '목록 수가 유효하지 않습니다.',
- 'sort.in' => '정렬 순서가 유효하지 않습니다.'
- ];
- }
- }
|