Support the ongoing development of →
Database Eloquent Testing
Last updated 2 years ago.

What about $table->nullableTimestamps(); instead of the $table->timestamps();

$table->nullableTimestamps(); 	Same as timestamps(), except allows NULLs
Last updated 2 years ago.

I don't want them set to null in the database. I want them filled in with the current time at the time of insert. BUT.. setting them to null in the seeder, causes Laravel to enter the correct values when it inserts, because the fields exist in the insert call.

I wonder why Laravel doesn't default to filling them automatically UNLESS I send in a value, then use the value I send?

What I'm looking for is an easier way to force them to be filled, and I'd much prefer the database to do it, so they are set to the database time, not the PHP (website) time.

If I want to do it in PHP, I can just add this at the top of the seeder $now = date('Y-m-d H:i:s'); and use it as the value, but then I get the webserver time, not the database time. It doesn't make much difference when I'm developing.. but it might in production... and some of the stuff I'm writing now will be used by others, so I'd prefer to solve the problem :)

What I'm doing with setting them to null works, but it's tedious to add it to every seeder that uses the Laravel timestamps() method and all together I've got hundreds of records to insert for all the tables.

If it doesn't exist yet, it's ok, but it would be a really nice to have feature.

Last updated 2 years ago.

Oh, ok

What about this in the migration,


Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

bgies bgies Joined 21 Jul 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.