| @@ 9-65 (lines=57) @@ | ||
| 6 | use Illuminate\Foundation\Http\FormRequest; |
|
| 7 | use Illuminate\Validation\Rule; |
|
| 8 | ||
| 9 | class DocumentRequest extends FormRequest |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * Determine if the user is authorized to make this request. |
|
| 13 | * |
|
| 14 | * @return bool |
|
| 15 | */ |
|
| 16 | public function authorize() |
|
| 17 | { |
|
| 18 | // only allow updates if the user is logged in |
|
| 19 | return backpack_auth()->check(); |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Get the validation rules that apply to the request. |
|
| 24 | * |
|
| 25 | * @return array |
|
| 26 | */ |
|
| 27 | public function rules() |
|
| 28 | { |
|
| 29 | return [ |
|
| 30 | 'type' => [ |
|
| 31 | 'required', |
|
| 32 | Rule::in(config('webfactor.documents.types')), |
|
| 33 | Rule::unique('documents') |
|
| 34 | ], |
|
| 35 | 'title' => 'required|min:5|max:255', |
|
| 36 | 'body' => 'required|string' |
|
| 37 | ]; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Get the validation attributes that apply to the request. |
|
| 42 | * |
|
| 43 | * @return array |
|
| 44 | */ |
|
| 45 | public function attributes() |
|
| 46 | { |
|
| 47 | return [ |
|
| 48 | 'type' => trans('webfactor::documents.type'), |
|
| 49 | 'title' => trans('webfactor::documents.title'), |
|
| 50 | 'body' => trans('webfactor::documents.body') |
|
| 51 | ]; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Get the validation messages that apply to the request. |
|
| 56 | * |
|
| 57 | * @return array |
|
| 58 | */ |
|
| 59 | public function messages() |
|
| 60 | { |
|
| 61 | return [ |
|
| 62 | // |
|
| 63 | ]; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| @@ 9-65 (lines=57) @@ | ||
| 6 | use Illuminate\Foundation\Http\FormRequest; |
|
| 7 | use Illuminate\Validation\Rule; |
|
| 8 | ||
| 9 | class DocumentUpdateRequest extends FormRequest |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * Determine if the user is authorized to make this request. |
|
| 13 | * |
|
| 14 | * @return bool |
|
| 15 | */ |
|
| 16 | public function authorize() |
|
| 17 | { |
|
| 18 | // only allow updates if the user is logged in |
|
| 19 | return backpack_auth()->check(); |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Get the validation rules that apply to the request. |
|
| 24 | * |
|
| 25 | * @return array |
|
| 26 | */ |
|
| 27 | public function rules() |
|
| 28 | { |
|
| 29 | return [ |
|
| 30 | 'type' => [ |
|
| 31 | 'required', |
|
| 32 | Rule::in(config('webfactor.documents.types')), |
|
| 33 | Rule::unique('documents')->ignore($this->id) |
|
| 34 | ], |
|
| 35 | 'title' => 'required|min:5|max:255', |
|
| 36 | 'body' => 'required|string' |
|
| 37 | ]; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Get the validation attributes that apply to the request. |
|
| 42 | * |
|
| 43 | * @return array |
|
| 44 | */ |
|
| 45 | public function attributes() |
|
| 46 | { |
|
| 47 | return [ |
|
| 48 | 'type' => trans('webfactor::documents.type'), |
|
| 49 | 'title' => trans('webfactor::documents.title'), |
|
| 50 | 'body' => trans('webfactor::documents.body') |
|
| 51 | ]; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Get the validation messages that apply to the request. |
|
| 56 | * |
|
| 57 | * @return array |
|
| 58 | */ |
|
| 59 | public function messages() |
|
| 60 | { |
|
| 61 | return [ |
|
| 62 | // |
|
| 63 | ]; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||