Has*_*qib 55 laravel php-carbon laravel-5
我有两个时间戳,我创建的edited_at和created_at(Laravel's)...在数据库中,两者都有类型时间戳和默认值0000-00-0000B 00:00 ...但是
var_dump(edited_at variable)正在给字符串.虽然var_dump(created_at variable)是对象/碳.这些时间戳有什么问题?
我必须在使用格式('U')转换为整数后比较两者.我只能在Carbon Object上调用这个方法.我怎样才能做到这一点?
luk*_*ter 136
首先,Eloquent自动将其时间戳(created_at,updated_at)转换为碳对象.你可以updated_at用来获得这个不错的功能,或者edited_at在你的模型中指定$dates属性:
protected $dates = ['edited_at'];
Run Code Online (Sandbox Code Playgroud)
现在回到你的实际问题.Carbon有一堆比较功能:
eq() 等于ne() 不等于gt() 比...更棒gte() 大于或等于lt() 少于lte() 小于或等于用法:
if($model->edited_at->gt($model->created_at)){
// edited at is newer than created at
}
Run Code Online (Sandbox Code Playgroud)
Carbon具有一堆带有助记符名称的比较功能:
用法:
if($model->edited_at->greaterThan($model->created_at)){
// edited at is newer than created at
}
Run Code Online (Sandbox Code Playgroud)
适用于nesbot / carbon 1.36.2
如果不确定所使用的Carbon版本,请运行此命令
$composer show "nesbot/carbon"
Run Code Online (Sandbox Code Playgroud)
文档:https : //carbon.nesbot.com/docs/#api-comparison
| 归档时间: |
|
| 查看次数: |
84847 次 |
| 最近记录: |