I'm trying to construct my app in a way that when it is implemented, the first step is to import (replicate) a whole heap of existing data from another system.
The key part of it is that there a whole lot of existing objects with a business reference identifier that must be kept as is.
After that however, all new items need a new identifier that must of course be unique.
So if don't override the boot function in my model, I can do the import just fine, but thereafter I run the risk of not having unique business reference identifiers.
If I do override the boot function (as shown below), then the import doesn't work properly, and the existing business reference identifiers are overwritten by a unique new identifier.
I doubt the solution is to try alter my model on the fly, so I'm stuck...
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->BusinessReference = uniqid('PRODUCT-');
});
}
INCOMING DATA
PRODUCT-1097
PRODUCT-1098
PRODUCT-1099
WHEN I OVERRIDE THE BOOT METHOD
PRODUCT-c2a7e56
PRODUCT-87afe52
PRODUCT-883eab3
The only option I can see is to save settings to a database table, and then check if the import has ever been done. If the import has never been done, then don't override the boot. If it has, well then don't.
But I'm wondering if there is a more elegant solution?
Thanks in advance