200576 * "columns" => array:1 [ * "transactions_banks.coupon_code" => "2001462387" * ] * ] * ] * * @return void */ public function apply(string $table, string $primaryKeyName, $config): void { /** @var DatabaseManager $db */ $db = app('db'); $primaryKeyValues = []; $whenGroup = []; foreach ($config as $configItem) { $primaryKey = $configItem['primary_key']; $primaryKeyValues[] = $primaryKey; foreach ($configItem['columns'] as $columnName => $columnValue) { if (!isset($whenGroup[$columnName])) { $whenGroup[$columnName] = []; } $whenGroup[$columnName][] = vsprintf('WHEN %s THEN %s', [ $primaryKey, $columnValue ]); } } $values = []; foreach ($whenGroup as $column => $whenArr) { /** @var Expression[] $whenArr */ $case = $db->raw(vsprintf('CASE %s %s END', [$primaryKeyName, implode(' ', $whenArr)])); $values[$column] = $case; } if (empty($values)) { return; } // DB::table('t_maquinetas as (,....)') // ->join( 'from ()') // UPDATE t_maquinetas //SET t_terminal_id = sub.id // FROM (SELECT id, id_antigo FROM t_terminal WHERE tipo = 1) as sub //WHERE sub.id_antigo = t_pos_id AND // (t_pdv_id IS NULL); $db->table($table) ->whereIn($primaryKeyName, $primaryKeyValues) ->update($values); } }