I am using an sql query like the following with the MySQL built in ADDDATE() function in Laravel Query Builder to increment the date by 1 day.
$sql = "UPDATE my_table
SET date_col = ADDDATE(date_col, INTERVAL 1 DAY)
WHERE id = {$the_id}";
DB::update($sql);
This is working fine and there is no reason to really change it. However, I first tried to use Query Builder with DB::raw as follows.
DB::table('my_table')
->where('id',$the_id)
->update(['date_col'=> DB::raw(ADDDATE(date_col, INTERVAL 1 DAY)]);
Is it possible to use the MySQL functions in this way? Is my syntax wrong or what?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire