belongsToMany(User::class, 'user_team', 'team_id', 'user_id', 'tid') ->orderByRaw(DB::raw('FIELD(ufutx_user_team.type, 1,2,0,3) asc')) ->orderBy('user_team.created_at', 'asc') ->withTimestamps() ->withPivot('mute','type', 'custom', 'nick', 'join_live'); } public function membersAsc() { return $this->belongsToMany(User::class, 'user_team', 'team_id', 'user_id', 'tid') ->withPivot('mute','type', 'custom', 'nick', 'join_live'); } public function owner() { return $this->belongsTo(User::class, 'owner'); } public function msgHistory() { return $this->belongsTo(MsgHistory::class, 'owner'); } public function getCustomAttribute($value) { return json_decode($value); } public function anchors() { return $this->hasMany(TeamLiveAnchor::class,'id', 'team_id'); } public function video(){ return $this->hasMany(Video::class, 'model_id') ->where('model', 'Team'); } }