【问题标题】:Timestamps in Laravel 5 got 0000-00-00Laravel 5 中的时间戳为 0000-00-00
【发布时间】:2015-06-09 15:48:56
【问题描述】:

我刚开始使用 Laravel 5,但时间戳有问题。当我为一张桌子播种时,一切都很顺利,我得到了例如

created_at
"2015-04-04 20:02:21"

updated_at
"2015-04-04 20:02:21"

但是当我使用Order::insert(array()) 我明白了:

created_at
"0000-00-00 00:00:00"

updated_at
"0000-00-00 00:00:00"

在 laravel 4 中我不需要手动设置时间戳,所以我相信我也不需要在那里设置。

【问题讨论】:

  • 你应该检查数据库的默认值。

标签: php mysql laravel timestamp


【解决方案1】:

我可以看到您正在使用 Eloquent。而不是使用insert() 方法,您应该像这样在数据库中创建新记录:

$order = new Order;
$order->save();

在这种情况下,Eloquent 将自动维护数据库表中的 created_at 和 updated_at 列

【讨论】:

  • 那就是。我使用“$order = new Order; $order->user_name = $request->input('username'); $order->save();”解决了问题但是 create([]) 不起作用,所以我需要重写我的数组
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多