Files
nexusphp/app/Models/NexusModel.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2021-04-02 19:48:41 +08:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class NexusModel extends Model
{
use HasFactory;
public $timestamps = false;
2022-05-13 03:12:38 +08:00
protected $perPage = 50;
2021-04-17 19:01:33 +08:00
/**
*
* @param \DateTimeInterface $date
* @return string
*/
protected function serializeDate(\DateTimeInterface $date)
{
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
}
2021-04-02 19:48:41 +08:00
2022-03-17 18:46:49 +08:00
/**
* Check is valid date string
*
* @see https://stackoverflow.com/questions/19271381/correctly-determine-if-date-string-is-a-valid-date-in-that-format
* @param $name
* @param string $format
* @return bool
*/
public function isValidDate($name, $format = 'Y-m-d H:i:s'): bool
{
$date = $this->getRawOriginal($name);
$d = \DateTime::createFromFormat($format, $date);
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
return $d && $d->format($format) === $date;
}
2021-04-02 19:48:41 +08:00
}