class RegRequest extends BaseRequest
{
public function rules()
{
return [
'l_name' => 'required|string|max:255',
'f_name' => 'required|string|max:255',
'm_name' => 'nullable|string|max:255',
'contact' => [
'required',
is_numeric($this->contact) ? 'digits:12' : 'email',
'unique:users,phone',
'unique:users,email',
],
'pass' => 'required|string|min:6|confirmed',
];
}
}
$validator = Validator::make($request->all(), [
'title' => [
'required',
'max:255',
function($attribute, $value, $fail) {
if ($value === 'foo') {
return $fail($attribute.' is invalid.');
}
},
],
]);