I have a logs table, which contains id, log_string, and created_at.
DDL for logs:
CREATE TABLE `logs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`log_string` varchar(255) NULL,
`created_at` datetime DEFAULT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4
The log_string column is by concat id and created_at and some string, and I do this by doing twice insert:
$log = App\Log::create(); //insert at the first time
$logString='This is log '.$log->id.'('.$log->created_at.')';
$log->update(['log_string'=>$logString]); //insert at the 2nd time
Could it possible to do that by just insert once?
There is a LAST_INSERT_ID() in MySQL but no THIS_INSERT_ID(), any idea?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34wGkud
via IFTTT
Aucun commentaire:
Enregistrer un commentaire