检查值是否存在,否则更新插入拉维尔


check if value exists update else insert laravel

我有一个函数,我想做的首先检查order_id存在,它会更新其他插入。请建议我

public function possstContract(){

        $postContracts = Contract::findOrNew(Input::get('order_id'));

    }
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);

updateOrCreate()查找具有第一个值数组的模型,然后创建它或仅使用第二个值数组更新它。