Trying to duplicate one column to another on MySQL using Laravel 8, the statement runs but values are not persisted.
DB::statement('UPDATE posts SET title = previous_title;');
Is there any solution to handle this case?
Trying to duplicate one column to another on MySQL using Laravel 8, the statement runs but values are not persisted.
DB::statement('UPDATE posts SET title = previous_title;');
Is there any solution to handle this case?
DB uses your default database connection from config/database.php DB credentials are mostly set in .env file.
When you use
DB::statement('UPDATE ....
the table is not specified anywhere and therefore it doesn't know on which table you want to make that update.
Solution 1
Use this to specify the table
DB::table('table_name')->statement('UPDATE ....
Solution 2
Use Eloquent because the table is set behind the scenes
User::update('column_name', NEW_ VALUE);
Have in mind this will update all rows on that table with same value if you don't use WHERE clause