Insert new record if not exist and update if exist

Hi, Im using laravel 5.3 and I have system config form.
as the title said, I want to do that step.
and here’s my Controller code

public function save(Request $request, $obj = null) {
    
        if (!$obj) {
            $obj = new Config;
            return $this->saveHandler($request, $obj);
        }
        else{
            $obj= Config::firstOrNew($id);
            return view('config.index',compact('compact')); 
        }
        
    }

it didn’t work, any idea ?

Insert new record if not exist and update if exist

INSERT … ON DUPLICATE KEY UPDATE …

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.