I want to make sure that the receiving data is a valid timestamp. is there a way to make sure starts_at and expired_at fields are timestamps?
$rules = [
'user_id' => 'required|int|exists:users,id',
'starts_at' => 'required|int|min:1',
'expires_at' => 'required|int|gt:starts_at',
];
2
Answers
You can define the multi-format date validation in your
AppServiceProvider
Now you can use the custom validation rule:
'starts_at' => 'new-format:"Y-m-d H:i:s.u","Y-m-d"'
You can use the
date
rule when validating timestamp. Then if you want to compare the two dates you can use thebefore
andafter
rule.