| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentCommunity\App\Models; |
| 4 | 4 | |
| 5 | +use FluentCommunity\App\Functions\Utility; | |
| 5 | 6 | use FluentCommunity\App\Models\Model; |
| 6 | 7 | use FluentCommunity\App\Models\XProfile; |
| 7 | 8 | |
| 8 | 9 | class SpaceUserPivot extends Model |
| @@ -14,9 +15,10 @@ | ||
| 14 | 15 | protected $fillable = [ |
| 15 | 16 | 'space_id', |
| 16 | 17 | 'user_id', |
| 17 | 18 | 'status', |
| 18 | - 'role' | |
| 19 | + 'role', | |
| 20 | + 'meta' | |
| 19 | 21 | ]; |
| 20 | 22 | |
| 21 | 23 | public function scopeBySpace($query, $spaceId) |
| 22 | 24 | { |
| @@ -54,5 +56,33 @@ | ||
| 54 | 56 | public function space() |
| 55 | 57 | { |
| 56 | 58 | return $this->belongsTo(BaseSpace::class, 'space_id', 'id')->withoutGlobalScopes(); |
| 57 | 59 | } |
| 60 | + | |
| 61 | + public function setMetaAttribute($value) | |
| 62 | + { | |
| 63 | + $this->attributes['meta'] = maybe_serialize($value); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public function getMetaAttribute($value) | |
| 67 | + { | |
| 68 | + if (!$value) { | |
| 69 | + return []; | |
| 70 | + } | |
| 71 | + | |
| 72 | + if (is_string($value)) { | |
| 73 | + $decodedMeta = json_decode($value, true); | |
| 74 | + if (is_array($decodedMeta)) { | |
| 75 | + $value = $decodedMeta; | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + $value = Utility::safeUnserialize($value); | |
| 80 | + | |
| 81 | + if (!is_array($value)) { | |
| 82 | + return []; | |
| 83 | + } | |
| 84 | + | |
| 85 | + return $value; | |
| 86 | + } | |
| 87 | + | |
| 58 | 88 | } |