From 8a3d3d1d344be4da7cfb203926d90c7c98b49f48 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 24 Oct 2024 17:05:37 -0500 Subject: [PATCH] fix:vapor doesn't like static attributes --- app/Models/Portfolio.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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;