Insert using DB table doesnt update timestamp

In laravel there are two ways to insert data/record, using DB table or using model, but i found a problem when inserting the data using DB table, the timestamp created_at and updated_at is showing '0000-00-00 00:00:00' as value.

That's the problem with DB table specially the insert method, you need to manually set the created_at and updated_at field.

Code like this will store timestamp as '0000-00-00 00:00:00':
'model_name' => 'F50',
'manufacture' => 'ferrari'));

Code like this will store timestamp properly:
'model_name' => 'F50',
'manufacture' => 'ferrari'));
or this:
$car = new Car();
$car->model_name = 'F50';
$car->manufacture = 'ferrari';

So you really need to use the model to insert data/record if you want the created_at and updated_at field to be set properly.

No comments :

Post a Comment

Leave A Comment...