1//setup Validator and passing request data and rules
2$validator = \Validator::make(request()->all(), [
3 'due_date' => 'required',
4 'template' => 'required'
5]);
6
7//hook to add additional rules by calling the ->after method
8$validator->after(function ($validator) {
9
10 if (request('event') == null) {
11 //add custom error to the Validator
12 $validator->errors()->add('event', 'Please select an event');
13 }
14
15});
16
17//run validation which will redirect on failure
18$validator->validate();
19
20//https://dcblog.dev/laravel-adding-custom-validation-errors