fix:vapor doesn't like static attributes

This commit is contained in:
hackerESQ
2024-10-24 17:05:37 -05:00
parent 3c41759cf3
commit 8a3d3d1d34
+9 -6
View File
@@ -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;