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

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

$table->nullableTimestamps(); 	Same as timestamps(), except allows NULLs
- http://laravel.com/docs/4.2/schema#adding-columns
Last updated 2 years ago.
0

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.
0

Oh, ok

What about this in the migration,


$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP'));

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

bgies bgies Joined 21 Jul 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.