if (request('event') == null) {
$validator->errors()->add('event', 'Please select an event');
}
// In the controller
throw IlluminateValidationValidationException::withMessages([
"one_thing" => ["Validation Message #1"],
"another_thing" => ['Validation Message #2']
]);
$this->validate([ // 1st array is field rules
'userid' =>'required|min:3|max:100',
'username' =>'required|min:3',
'password' =>'required|max:15|confirmed',
], [ // 2nd array is the rules custom message
'required' => 'The :attribute field is mandatory.'
], [ // 3rd array is the fields custom name
'userid' => 'User ID'
]);
php artisan make:rule RuleName
namespace AppRules;
use IlluminateContractsValidationRule;
class GreaterThanTen implements Rule
{
// Should return true or false depending on whether the attribute value is valid or not.
public function passes($attribute, $value)
{
return $value > 10;
}
// This method should return the validation error message that should be used when validation fails
public function message()
{
return 'The :attribute must be greater than 10.';
}
}