Skip to content
Advertisement

Laravel seeder with Eloquent give timestamp null

I am trying to insert static data, with the help of the seeder and Eloquent as bellow.

JavaScript

Even after using Eloquent i am getting timestamp null in database.

Advertisement

Answer

The timestamp columns (created_at and updated_at) will be assigned automatically only if you are using the Eloquent
save() method and create method are Eloquent.
While insert method is not Eloquent, it’s a query builder method. So use create method instead :

JavaScript

When you are using query builder, you have to created_at and updated_at value by yourself :

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement