1
我有一个控制器正在通过请求对象更新模型。它看起来正在更改Laravel模型“开始”日期属性
$save_series = Series::where('id','=',$request->input('data.item.id'))->with('booking')->first();
$save_series->name = $request->input('data.item.name');
$save_series->color = str_replace('#', '', $request->input('data.item.color'));
$save_series->production_company = $request->input('data.item.production_company');
$save_series->booking->start = $request->input('data.item.booking.start');
$save_series->booking->end = $request->input('data.item.booking.end');
$save_series->booking->save();
$save_series->save();
当我保存这个相关的“预订”对象更新。如果“结束”日期属性发生更改,则“开始”属性的时间设置为当前时间;这不应该是这样!它似乎完全忽略了解析的$请求开始时间。
在预订的相关模型上,我已经放置了一个setter mutator来查看问题是否在该点之前驻留 - 日期正确解析,但一旦它遇到它已更改的数据库。我(只是为了本次测试)的设置是这样的:
public function setStartAttribute($time) {
error_log(":::::::::::TEST BELOW:");
error_log($time);
return $time;
}
错误日志的结果是:
PHP message: :::::::::::TEST BELOW:
PHP message: 2016-10-27 00:00:00
不过的“开始”此记录的数据库字段上写着:
2016-10-27 13:07:53
请有人能解释这里发生了什么;我完全失去了!
- 的要求其他信息 -
迁移导致的问题:它解决了该问题
Schema::create('calendar_events', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->integer('calendar_event_type')->references('id')->on('calendar_event_types');
$table->timestampTz('start');
$table->timestampTz('end');
$table->softDeletes();
$table->timestamps();
});
迁移分辨率:
Schema::create('calendar_events', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->integer('calendar_event_type')->references('id')->on('calendar_event_types');
$table->dateTime('start');
$table->dateTime('end');
$table->softDeletes();
$table->timestamps();
});
我假定这有什么与MySQL支持timestampTz和我发送给数据库的格式有关。改变了这个我的问题现在已经解决了,非常感谢@FrankProvost!
我假设现在不可能保持时区。在我的使用案例中,时区不会成为问题,但它会很好。
唯一至极可以说明这一点,是你的时间是FORMATT 00H-12H – WebFreak
的'$ time'日期时间格式可能是问题 – Wistar
@ThibaultDumas是“2016-10-27 13:07:53”被解析的问题?它是否期待Carbon实例或其他? – kirgy