1
我似乎无法让我的代码工作100%。我试图让我的代码以这样的方式工作:更新数据库字段,如果数据存在
如果列值为空($id = columnName
),则插入该行。如果发现该值为“$id
”,则更新已保存在数据库中的值。
功能:
$socialCheck = SocialSettings::where($id)->first();
$socialInsert = new SocialSettings;
$value = Request::input('value');
if(SocialSettings::where_not_null($id)){
$socialInsert->$id = $value;
$socialInsert->save();
}else{
$socialCheck->update($value);
}
}
如果您使用的是mysql并且愿意使用['DB :: raw()'](http://fideloper.com/laravel-raw-queries)准备绑定语句,那么您可以使用['REPLACE INTO' ](http://stackoverflow.com/questions/19820724/replace-into-query-syntax)陈述 –
你找到解决办法吗? –