問題描述
我有一些這樣的代碼
$editStuState = StuAtt::where('studentId' , '=' , $id)->first();
$editStuState -> leave +=1;
$editStuState -> present = $editStuState -> present-1;
$editStuState->update();
//OR
$editStuState->save();
return 'this is good';
我無法保存或更新我的數(shù)據(jù),當(dāng)我刪除更新和保存相關(guān)行時(shí),它可以打印文本.
I can't save or Update my data, when I remove Update and Save related line it can print text.
這是dd($editStuState)
數(shù)據(jù)
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 得到這個(gè)錯(cuò)誤
I also got this error form laravel 5.6 it
InvalidArgumentException
Trailing data
推薦答案
如果您使用 Postgres,則必須向模型添加一些行.這是因?yàn)?Postgres 中的 TIME WITH TIMEZONE.
If you are using Postgres you have to add some lines to your Model(s). It happens because of TIME WITH TIMEZONE in Postgres.
另請(qǐng)閱讀 Date Mutators
因?yàn)?Laravel 已經(jīng)支持此功能,只需在您的模型中放置以下行以覆蓋該模型的默認(rèn)日期格式:https://laravel.com/docs/5.7/eloquent-mutators#date-mutators
Please also read Date Mutators
as Laravel already has support for this baked in, simply put below line in your Model to override the default dateFormat for that model: https://laravel.com/docs/5.7/eloquent-mutators#date-mutators
轉(zhuǎn)到您的應(yīng)用程序/模型(在 app
文件夾下,exp. User,SomeModel)添加以下行:
Go to your App/Model (under app
folder, exp. User, SomeModel) add below line:
protected $dateFormat = 'Y-m-d H:i:sO';
最佳
這篇關(guān)于保存模型時(shí) Laravel 模型尾隨數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!