'How can I convert this SQL to use Laravel Query builder?

This Is my SQL:

DELETE FROM valores_integracao_marketplace_fornecedor_user 
WHERE configuracao_marketplace_id (
        SELECT id FROM configuracoes_marketplace
         WHERE chave = 'something');

I have tried the following

DB::table('valores_integracao_marketplace_fornecedor_user')->whereExists(function($query){
    $query->select('configuracao_marketplace_id')
    ->from('valores_integracao_marketplace_fornecedor_user')
    ->where('chave', '=', 'something');
})->delete();

But this deletes the wrong thing



Solution 1:[1]

Youre subquery in SQL looks in the configuracoes_marketplace table, but the PHP version looks in valores_integracao_marketplace_fornecedor_user.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander Morland