eloquent: prevent duplicate rows

To prevent duplicate┬ádatabase entries there is a built-in method in Eloquent. // data to insert $data = [ ‘col1’ => ‘A’, ‘col2’ => ‘B’ ] // perform a check over col1 and col2 and insert/update the data $instance = MyModel::updateOrCreate([ ‘col1’ => $data[‘col1’], ‘col2’ => $data[‘col2’] ], $data);