1

I have a function where what i want to do first check order_id exists it update else insert. Please suggest me

public function possstContract(){


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


    }

1 Answer 1

2
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() looks for a model with the first array of values, and then either creates it or just updates it with the second array of values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.