保存模型时的Laravel模型尾随数据 [英] Laravel model Trailing Data when save the model
本文介绍了保存模型时的Laravel模型尾随数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些这样的代码
$editStuState = StuAtt::where('studentId' , '=' , $id)->first();
$editStuState -> leave +=1;
$editStuState -> present = $editStuState -> present-1;
$editStuState->update();
//OR
$editStuState->save();
return 'this is good';
我无法保存或更新我的数据, 当我删除更新并保存"相关行时,它可以打印文本.
I can't save or Update my data, when I remove Update and Save related line it can print text.
这是dd($editStuState)
数据
StuAtt {#382 ▼
#table: "stu_attendance"
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▼
"id" => "7"
"studentId" => "1"
"present" => "2"
"absent" => "1"
"leave" => "10"
"created_at" => "2018-04-16 11:17:41.176898"
"updated_at" => "2018-04-16 06:47:41.000000"
]
#original: array:7 [▼
"id" => "7"
"studentId" => "1"
"present" => "2"
"absent" => "1"
"leave" => "10"
"created_at" => "2018-04-16 11:17:41.176898"
"updated_at" => "2018-04-16 06:47:41.000000"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
我也从laravel 5.6得到了这个错误信息
I also got this error form laravel 5.6 it
InvalidArgumentException
Trailing data
推荐答案
跟踪数据是Carbon错误,这是因为您可能使用了Postgres,并且日期返回了毫秒.
Trailing data is a Carbon error, it's because you probably use Postgres and your date returns milliseconds.
"created_at" => "2018-04-19 07:01:19.929554"
您可以将以下方法添加到(基本)模型中.
You can add the following method to your (base) model.
public function getDateFormat()
{
return 'Y-m-d H:i:s.u';
}
如果您在Postgres中使用TIME WITH TIMEZONE,则格式应为:
If you are using TIME WITH TIMEZONE in Postgres then the format should be:
Y-m-d H:i:s.uO
这篇关于保存模型时的Laravel模型尾随数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文