Skip to content

Instantly share code, notes, and snippets.

@itsrachelfish
Created February 6, 2017 04:54
Show Gist options
  • Save itsrachelfish/6c4b71345e7598154a635b84b927c024 to your computer and use it in GitHub Desktop.
Save itsrachelfish/6c4b71345e7598154a635b84b927c024 to your computer and use it in GitHub Desktop.
Laravel custom validation messages
<?php
...
Validator::extend('time', function($attribute, $value, $parameters)
{
$value = trim($value);
// Check against 12 hour time (with AM/PM) or 24 hour time
$twelve = date_parse_from_format('h:i a', $value);
$twentyfour = date_parse_from_format('H:i', $value);
if($twelve['error_count'] === 0 || $twentyfour['error_count'] === 0)
{
return true;
}
return false;
});
...
<?php
...
'custom' =>
[
'password' =>
[
'hashed' => "Invalid password entered"
],
'validation' =>
[
'time' => "DEPR DERP",
],
'custom_end_time.time' => "why in the world",
'validation.time' => 'HELLOO???',
'time' => "uhhh",
'*.time' => 'what????'
],
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment