public static function bootInventoryTrait()
{
/*
* Assign the current users ID while the item
* is being created
*/
static::creating(function (Model $record) {
$record->setAttribute('user_id', Helper::getCurrentUserId());
});
/*
* Generate the items SKU once it's created
*/
static::created(function (Model $record) {
$record->generateSku();
});
/*
* Generate an SKU if the item has been assigned a category,
* this will not overwrite any SKU the item had previously
*/
static::updated(function (Model $record) {
if ($record->category_id !== null) {
$record->generateSku();
}
});
}