Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查值是否存在更新否则插入laravel_Php_Laravel - Fatal编程技术网

Php 检查值是否存在更新否则插入laravel

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

我有一个函数,在这个函数中,我首先要做的是检查订单id是否存在,然后更新或插入。请推荐我

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