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?
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';
}
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 ;-)