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

rorymcdaniel's avatar

Slowly Rebuilding a Legacy PHP app in Laravel

I'm working on a mammoth legacy PHP app that was built with no framework at all and slowly migrating it to Laravel. One issue I'm coming up with is that the basic idea of soft deletes was used, but instead of a deleted_at column, there's a boolean IsActive column in the database.

Other than writing a bunch of migrations and slowly migrating these models one by one (there are 119 tables with this column that I need to refactor), does anyone have any suggestions on what might make this process easier? Honestly, my best idea right now is just to add a deleted_at column, add the SoftDeletes trait, and then write a console command that iterates over each of the models in question and sets the deleted_at date to some specific date if IsActive is set to 0.

Am I on the right track here or does anyone have any better ideas?

0 likes
4 replies
tykus's avatar

It looks like you can set a DELETED_AT constant on each of the models:

See the following in the trait:

    /**
     * Get the name of the "deleted at" column.
     *
     * @return string
     */
    public function getDeletedAtColumn()
    {
        return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
    }


ohffs's avatar

I feel your pain - I'm slooowwwwlllyyy migrating an old PHPv4 (yes) app that's c100k lines of impenetrable gibberish built up over 10-15 years :-/ It also has a home-grown "soft deletes" - although the soft-delete column name changes depending who was writing that particular bit of code. Which is... nice...

If I were you I'd go with your migration plan and add the extra column. It's the 'path of least surprises' I think. You know you haven't altered anything for the existing code - and you don't have to alter the behaviour of Laravel. Anyone who comes after you will thank you for sticking with the defaults ;-)

Good luck! :-)

1 like
phpMick's avatar

I would add a deleted_at column, then set it with an UPDATE, based on the boolean field.

Christofer's avatar

Trying to speed up this change sounds risky, may lead to even more time loss. I would take the hit of refactoring it, test then test and test again.

Please or to participate in this conversation.