1//For float, must use numeric validator
2
3/**
4 * Get the validation rules that apply to the request.
5 *
6 * @return array
7 */
8public function rules()
9{
10 return [
11 'field' => 'numeric'
12 ];
13}
1use Illuminate\Support\Facades\Validator;
2use Illuminate\Validation\Rule;
3
4Validator::make($data, [
5 'zones' => [
6 'required',
7 Rule::in(['first-zone', 'second-zone']),
8 ],
9]);
1/**
2 * Store a new blog post.
3 *
4 * @param Request $request
5 * @return Response
6 */
7public function store(Request $request)
8{
9 $validatedData = $request->validate([
10 'title' => 'required|unique:posts|max:255',
11 'body' => 'required',
12 ]);
13
14 // The blog post is valid...
15}
1public function store()
2{
3 $this->validate(request(), [
4 'song' => [function ($attribute, $value, $fail) {
5 if ($value <= 10) {
6 $fail(':attribute needs more cowbell!');
7 }
8 }]
9 ]);
10}
11
1/**
2 * Configure the validator instance.
3 *
4 * @param \Illuminate\Validation\Validator $validator
5 * @return void
6 */
7public function withValidator($validator)
8{
9 $validator->after(function ($validator) {
10 if ($this->somethingElseIsInvalid()) {
11 $validator->errors()->add('field', 'Something is wrong with this field!');
12 }
13 });
14}