Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

faraz73's avatar

nullable() for timestamp

Hi .. i'm using $table->timestamps('published_at')->nullable() in migrations, and i got an error that nullable() on null. @jeffry in larcasts laravel6 migration 101 uses this code .. but i got nullable() on null error. nullable() method does not work in timestamps(). why ??

0 likes
3 replies
siangboon's avatar

$table->timestamps() refer to 'created_at' and 'updated_at'

try

$table->timestamp('published_at')->nullable()
munazzil's avatar

You can use as like below in your related model,

       public $timestamps = false;

else use below also with that,

    public $incrementing = false;
Snapey's avatar
Snapey
Best Answer
Level 122

Jeffrey does not use your code. He has timestamps() and then an extra line for timestamp(). Note that these are different functions. you need both lines.

$table->timestamps();
$table->timestamp('published_at')->nullable();

ignore @munazzil , he's inventing his own unrelated problems again

3 likes

Please or to participate in this conversation.