<?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; use Illuminate\Contracts\Validation\Validator; class SampleRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ 'name' => 'bail|required|max:100', 'number' => 'bail|required|integer|max:10000000', ]; } public function withValidator(Validator $validator) { // number の入力値が50より大きい場合のみ、必須と最大文字数のチェックを行う $validator->sometimes('type', 'required|max:100', function () { return $this->input->number > 50; }); } public function attributes() { return [ 'name' => '名前', 'number' => '数', 'type' => 'タイプ', ]; } }
コメント