php – Laravel打印created_at时追踪数据
发布时间:2020-12-14 19:34:06 所属栏目:大数据 来源:网络整理
导读:我在laravel 5.6中更新模型数据时遇到问题, 经过很多次,我发现实际上问题在于created_at和updated_at. 我的代码: $editStuState = StuAtt::where('studentId','=',1007)-first();dd($editStuState - created_at); 和dd($editStuState) StuAtt {#382 ▼ #tab
我在laravel 5.6中更新模型数据时遇到问题,
经过很多次,我发现实际上问题在于created_at和updated_at. 我的代码: $editStuState = StuAtt::where('studentId','=',1007)->first(); dd($editStuState -> created_at); 和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" => "3" "studentId" => "1007" "present" => "7" "absent" => "2" "leave" => "6" "created_at" => "2018-04-19 07:01:19.929554" "updated_at" => "2018-04-19 02:31:19.000000" ] #original: array:7 [▼ "id" => "3" "studentId" => "1007" "present" => "7" "absent" => "2" "leave" => "6" "created_at" => "2018-04-19 07:01:19.929554" "updated_at" => "2018-04-19 02:31:19.000000" ] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [?] } 出现错误 InvalidArgumentException Trailing data 错误在哪里以及如何解决? 解决方法
尾随数据是Carbon错误,因为您可能使用Postgres并且您的日期返回毫秒.
您可以将以下方法添加到(基础)模型中. public function getDateFormat() { return 'Y-m-d H:i:s.u'; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |