# fluent-community/2.7.7/app/Models/SpaceUserPivot.php

FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS &amp; Online Courses, version 2.7.7. 89 lines.

- Page: https://pluginprobe.com/plugins/fluent-community/2.7.7/code/app/Models/SpaceUserPivot.php
- Raw: https://pluginprobe.com/plugins/fluent-community/2.7.7/raw/app/Models/SpaceUserPivot.php
- Modified: 2026-02-19T15:17:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-community/2.7.7/code/app/Models/SpaceUserPivot.php#L10-L20`.

```php
<?php

namespace FluentCommunity\App\Models;

use FluentCommunity\App\Functions\Utility;
use FluentCommunity\App\Models\Model;
use FluentCommunity\App\Models\XProfile;

class SpaceUserPivot extends Model
{
    protected $table = 'fcom_space_user';

    protected $guarded = ['id'];

    protected $fillable = [
        'space_id',
        'user_id',
        'status',
        'role',
        'meta'
    ];

    public function scopeBySpace($query, $spaceId)
    {
        if (!$spaceId) {
            return $query;
        }

        $query->where('space_id', $spaceId);

        return $query;
    }


    public function scopeByUser($query, $userId)
    {
        if (!$userId) {
            return $query;
        }

        $query->where('user_id', $userId);

        return $query;
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'ID');
    }

    public function xprofile()
    {
        return $this->belongsTo(XProfile::class, 'user_id', 'user_id');
    }

    public function space()
    {
        return $this->belongsTo(BaseSpace::class, 'space_id', 'id')->withoutGlobalScopes();
    }

    public function setMetaAttribute($value)
    {
        $this->attributes['meta'] = maybe_serialize($value);
    }

    public function getMetaAttribute($value)
    {
        if (!$value) {
            return [];
        }

        if (is_string($value)) {
            $decodedMeta = json_decode($value, true);
            if (is_array($decodedMeta)) {
                $value = $decodedMeta;
            }
        }

        $value = Utility::safeUnserialize($value);

        if (!is_array($value)) {
            return [];
        }

        return $value;
    }

}

```
