diff --git a/app/Models/Portfolio.php b/app/Models/Portfolio.php index e25268e..6b41029 100644 --- a/app/Models/Portfolio.php +++ b/app/Models/Portfolio.php @@ -28,12 +28,6 @@ class Portfolio extends Model { parent::boot(); - static::creating(function ($portfolio) { - - // enable queued jobs to create portfolios with owners - static::$owner_id = auth()->user()?->id ?? $portfolio->attributes['owner_id']; - }); - static::saving(function ($portfolio) { unset($portfolio->owner_id); }); @@ -97,6 +91,15 @@ class Portfolio extends Model return $this->where(['wishlist' => false]); } + public function setOwnerIdAttribute($value) + { + // enable queued jobs to create portfolios with owners + if (!auth()->user()?->id && !$this->owner_id) { + $this->attributes['owner_id'] = $value; + static::$owner_id = $value; + } + } + public function getOwnerIdAttribute() { return $this->owner?->id;