myvideogamelist.com/app/Rules/GameReleaseDates.php
Jimmy Brancaccio b39ecf1638 Initial Commit
The initial public commit of MVGL website code.
2024-01-14 13:51:43 -06:00

32 lines
796 B
PHP

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\InvokableRule;
use Illuminate\Support\Carbon;
class GameReleaseDate implements InvokableRule
{
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke($attribute, $value, $fail)
{
if ($value === 'TBD' || $value === 'EA') {
return true;
}
try {
Carbon::createFromFormat('F j, Y', $value);
} catch (Exception $e) {
$fail('The release date must be in the format of Month Day, Year (ex. March 10, 2000), TBD or EA.');
}
return true;
}
}