Php Laravel/流明投射时间戳到int

Php Laravel/流明投射时间戳到int,php,laravel,casting,lumen,Php,Laravel,Casting,Lumen,使用$table->timestamp('createdAt')创建时间戳 获取unix时间戳值。我在模型中将其铸造为: protected $casts = [ 'createdAt' => 'datetime:U', ] 但是,$model->toArray()将unix时间戳作为字符串而不是int/number获取 "createdAt"=> "1537003313", 应该是: "createdAt"=> 1537003313, 我使用toArray方法来

使用
$table->timestamp('createdAt')创建时间戳
获取unix时间戳值。我在模型中将其铸造为:

protected $casts = [
    'createdAt' => 'datetime:U',
]
但是,
$model->toArray()
将unix时间戳作为字符串而不是int/number获取

"createdAt"=> "1537003313",
应该是:

"createdAt"=> 1537003313,

我使用toArray方法来避免迭代行。所以
(int)$model->createdAt不是一个选项。

尝试使用int casting

(int)$timestamp
你的情况应该是这样的

$casts['createdAt'] = (int)$casts['createdAt'];

阅读此内容了解更多信息:

请参阅此。希望它能对你有所帮助。问题更多的是如何使用模型或其他东西在拉威尔的末端实现。我不能使用显式类型转换。