Php 检查值是否存在更新否则插入laravel
我有一个函数,在这个函数中,我首先要做的是检查订单id是否存在,然后更新或插入。请推荐我Php 检查值是否存在更新否则插入laravel,php,laravel,Php,Laravel,我有一个函数,在这个函数中,我首先要做的是检查订单id是否存在,然后更新或插入。请推荐我 public function possstContract(){ $postContracts = Contract::findOrNew(Input::get('order_id')); } updateOrCreate()查找具有第一个值数组的模型,然后创建它或仅使用第二个值数组更新它 public function postContract(){ $pos
public function possstContract(){
$postContracts = Contract::findOrNew(Input::get('order_id'));
}
updateOrCreate()
查找具有第一个值数组的模型,然后创建它或仅使用第二个值数组更新它
public function postContract(){
$postContracts = Contract::updateOrCreate([
'order_id'=>Input::get('order_id')
],[
'content'=>Input::get("content"),
'signature'=>Input::get("signature"),
'created_by'=>Input::get("created_by"),
'updated_by'=>Input::get("updated_by"),
]);
return Response::json([
"success" => true,
"message" => "Contract Added Successfully"
], 200);