Search code examples
laraveldate-formatsoft-delete

soft delete not working when $dateFormat="U"


Im trying to import softDelete to current project. In migration file i added:

$table->softDeletes();

In model. I got this:

protected $dateFormat = 'U';

But deleting not working as i expected.

Invalid datetime format: 1292 Incorrect datetime value: '1579188678' for column 'deleted_at'

So my question is how can i use deleted_at as unix time or how to use deleted_at column as timestamp when protected $dateFormat = 'U'; this was still exist. Thanks in advance.


Solution

  • Since you want to use the Unix timestamp as format, you can't use the ->sofDeletes() and ->timestamps() methods in migration, you need to set them yourself as integers

    $table->integer('created_at')->nullable();
    $table->integer('updated_at')->nullable();
    $table->integer('deleted_at')->nullable();