I need update key in table catalog and I write query (mysql query is right):
update attributes a inner join catalog c on a.parent_id = c.id set a.key = c.left_key
and with Laravel DB:
DB::table('attributes as a')
->join(catalog as c', 'a.parent_id', '=', 'c.id')
->update([ 'a.key' => 'c.left_key' ]);
It's right query, but DB::table ... make all key in table catalog to 0. I write
DB::statement('update attributes a inner join catalog c on a.parent_id = c.id set a.key = c.left_key;');
And it's work! But I don't understand why DB::table with join and update don't work
You can try as:
DB::table('attributes as a')
->join('catalog as c', 'a.parent_id', '=', 'c.id')
->update([ 'a.key' => DB::raw("`c`.`left_key`") ]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With