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

diamondfish's avatar

Soft delete modifies custom date field in database table

I have a table with a field 'expires_at'. When soft deleting an entry and all it's children, it has it's deleted_at and updated_at field change. But for some reason, it also changes my custom field expires_at to the same value. Is this the expected behaviour, or am I doing something wrong?

Migrations:

Schema::create( 'licensegroups', function ( Blueprint $table ) {
            $table->increments( 'id' );
            $table->string( 'name' );
            $table->timestamp( 'expires_at' );
            $table->timestamps();
            $table->softDeletes();
        } );

Schema::create( 'licenses', function ( Blueprint $table ) {
            $table->increments( 'id' );
            $table->integer( 'licensegroup_id' )->unsigned();;
            $table->integer( 'quantity' )->unsigned();;
            $table->string( 'key' );
            $table->timestamps();
            $table->softDeletes();
    
            $table->foreign('licensegroup_id')->references('id')->on('licensegroups')->onDelete('cascade');
        } );

Models:

class Licensegroup extends Model
{
    use SoftDeletes;
    protected $dates = ['deleted_at'];

    // ...

    public function licenses()
    {
        return $this->hasMany( License::class );
    }
    
    public static function boot()
    {
        parent::boot();
        
        static::deleting(function($licensegroup)
        {
            $licensegroup->licenses()->delete();
        });
    
        static::restoring(function($licensegroup)
        {
            $licensegroup->licenses()->restore();
        });
    }
}

class License extends Model
{
    use SoftDeletes;
    protected $dates = ['deleted_at'];

    // ...
}

I then use $licensegroup->delete(); to delete the parent with it's children.

0 likes
3 replies
diamondfish's avatar

I've still no solution for this, and I'd really appreciate help in any form. Is there some clever way I can debug this? Is there some more in-depth documentation that I've missed on soft delete somewhere?

pom's avatar
pom
Best Answer
Level 21

Change

$table->timestamp( 'expires_at' );

to

$table->datetime( 'expires_at' );

1 like
diamondfish's avatar

Thank you so much @pom ! It works! I just assumed it was called timestamp and assumed the problem lied elsewhere.

Please or to participate in this conversation.