love_php/app/Models/App/Team.php
2026-04-02 09:20:51 +08:00

51 lines
1.4 KiB
PHP

<?php
namespace App\Models\App;
use Illuminate\Support\Facades\DB;
use App\Models\User;
use App\Models\TeamLiveAnchor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Video;
class Team extends Model
{
use SoftDeletes;
public function members()
{
return $this->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');
}
}