【发布时间】:2014-04-09 16:49:14
【问题描述】:
您好,我想创建自己的时间戳,它可以与碳 diffIn 函数一起使用
public function up()
{
Schema::create('global_limits', function(Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('c_limiter');
$table->timestamp('time_comment');
$table->timestamps('');
});
}
这是我如何创建 timespam 到 time_comment
$first_limit = new Limiter;
$first_limit->c_limiter = 1;
$first_limit->user_id = $id;
$first_limit->time_comment = new DateTime;
$first_limit->save();
当
$user = User::find(1)->limits;
echo $user->time_comment 我得到 2014-04-09 18:20:55 但是当我这样做时
echo $user->time_comment->diffInSeconds();
Call to a member function diffInSeconds() on a non-object on proper timestamp.
奇怪的是,当我用 created_at 和 uptaded_at 做同样的事情时,它工作正常。
echo $user->created_at->diffInSeconds();
我知道我可以为此使用 updated_at 但我想使用 time_comment 我有我的理由。
我不想要 diffForHumans,因为我的目标是使用
if($user->time_comment->diffInSeconds() > 500)
{do something)else {do this}
【问题讨论】: