| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Models; |
| 4 |
|
| 5 |
use FluentCommunity\App\Models\Model; |
| 6 |
use FluentCommunity\App\Models\XProfile; |
| 7 |
|
| 8 |
class SpaceUserPivot extends Model |
| 9 |
{ |
| 10 |
protected $table = 'fcom_space_user'; |
| 11 |
|
| 12 |
protected $guarded = ['id']; |
| 13 |
|
| 14 |
protected $fillable = [ |
| 15 |
'space_id', |
| 16 |
'user_id', |
| 17 |
'status', |
| 18 |
'role' |
| 19 |
]; |
| 20 |
|
| 21 |
public function scopeBySpace($query, $spaceId) |
| 22 |
{ |
| 23 |
if (!$spaceId) { |
| 24 |
return $query; |
| 25 |
} |
| 26 |
|
| 27 |
$query->where('space_id', $spaceId); |
| 28 |
|
| 29 |
return $query; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
public function scopeByUser($query, $userId) |
| 34 |
{ |
| 35 |
if (!$userId) { |
| 36 |
return $query; |
| 37 |
} |
| 38 |
|
| 39 |
$query->where('user_id', $userId); |
| 40 |
|
| 41 |
return $query; |
| 42 |
} |
| 43 |
|
| 44 |
public function user() |
| 45 |
{ |
| 46 |
return $this->belongsTo(User::class, 'user_id', 'ID'); |
| 47 |
} |
| 48 |
|
| 49 |
public function xprofile() |
| 50 |
{ |
| 51 |
return $this->belongsTo(XProfile::class, 'user_id', 'user_id'); |
| 52 |
} |
| 53 |
|
| 54 |
public function space() |
| 55 |
{ |
| 56 |
return $this->belongsTo(BaseSpace::class, 'space_id', 'id')->withoutGlobalScopes(); |
| 57 |
} |
| 58 |
} |
| 59 |
|