创建模型验证器,验证数据正确性
This commit is contained in:
@@ -17,4 +17,24 @@ class OperationNotice extends Model
|
||||
'notice_type' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
public function setPublishAtAttr($value)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return 0;
|
||||
}
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (is_string($value)) {
|
||||
if (ctype_digit($value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
$ts = strtotime($value);
|
||||
if ($ts !== false) {
|
||||
return $ts;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user