Skip to content

Instantly share code, notes, and snippets.

@pepeloper
Created May 8, 2018 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepeloper/9e059f61b1854fe79786cf367f276b6e to your computer and use it in GitHub Desktop.
Save pepeloper/9e059f61b1854fe79786cf367f276b6e to your computer and use it in GitHub Desktop.
Laravel validation rule for request
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Carbon\Carbon;
class Timestamp implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
if (!intval($value)) {
return false;
}
return (boolean) @Carbon::createFromTimestamp($value);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The :attribute must be a valid timestamp.';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment