79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Live;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Live extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
public function register(){
|
|
return $this->hasMany(Viewer::class);
|
|
}
|
|
|
|
public function viewer()
|
|
{
|
|
return $this->belongsToMany(Viewer::class);
|
|
}
|
|
|
|
public function liveviewer()
|
|
{
|
|
return $this->hasMany(LiveViewer::class);
|
|
}
|
|
|
|
public function class()
|
|
{
|
|
return $this->belongsTo(LiveClass::class, 'class_id');
|
|
}
|
|
|
|
public function video(){
|
|
return $this->hasOne(Video::class);
|
|
}
|
|
|
|
public function viewershare(){
|
|
return $this->hasMany(ViewerShare::class);
|
|
}
|
|
|
|
public function giftorder(){
|
|
return $this->hasMany(GiftOrder::class);
|
|
}
|
|
|
|
public function teacher(){
|
|
return $this->belongsTo(Anchor::class, 'anchor_id');
|
|
}
|
|
|
|
public function question(){
|
|
return $this->hasMany(Question::class);
|
|
}
|
|
|
|
public function task(){
|
|
return $this->hasMany(Task::class);
|
|
}
|
|
|
|
public function winner(){
|
|
return $this->belongsToMany(Viewer::class, 'live_winner');
|
|
}
|
|
|
|
public function lottery(){
|
|
return $this->hasMany(Lottery::class);
|
|
}
|
|
|
|
public function messenger(){
|
|
return $this->hasMany(Messenger::class);
|
|
}
|
|
public function getTeacherUserId(){
|
|
$living_teacher_id = $this->anchor_id;
|
|
$teacher_viewer_id = Anchor::where('id', $living_teacher_id)->value('id');
|
|
if(!empty($teacher_viewer_id)){
|
|
$living_user_id = Viewer::where('id', $teacher_viewer_id)->value('user_id');
|
|
if(!empty($living_user_id)){
|
|
return $living_user_id;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
}
|