Laravel 里的 save 方法保存,怎么数据库里没有数据?保存失败了会有什么错误信息反映?
$new = News::firstOrNew($request->except('_token'));
//dd($new);
$new->save();
return redirect()->to('/news/' . $new->id);
我dd打印的new对象是:
News {#268 ▼
fillable: array:3 [▼
0 => "new_title"
1 => "new_author"
2 => "new_body"
]
connection: "mysql"
table: null
primaryKey: "id"
keyType: "int"
+incrementing: true
with: []
withCount: []
perPage: 15
+exists: false
+wasRecentlyCreated: false
attributes: array:3 [▼
"new_title" => "qwe"
"new_author" => "qi"
"new_body" => "wwwww"
]
original: []
casts: []
dates: []
dateFormat: null
appends: []
events: []
observables: []
relations: []
touches: []
+timestamps: true
hidden: []
visible: []
guarded: array:1 [▼
0 => "*"
]
}
但是myadmin数据库里却没有保存这条数据.
推荐文章: