36 lines
790 B
PHP
36 lines
790 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
|
|
class UserTalk extends Model
|
|
{
|
|
use HasFactory,HasDateTimeFormatter;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'talk_content',
|
|
'praise_num',
|
|
'is_show',
|
|
];
|
|
|
|
public function user(){
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function praiseUsers(){
|
|
return $this->belongsToMany(User::class, 'user_praise_talks', 'user_id', 'talk_id');
|
|
}
|
|
|
|
public function praise(){
|
|
return $this->hasMany(UserPraiseTalk::class, 'talk_id');
|
|
}
|
|
|
|
public function hasPraise($user_id){
|
|
return $this->praise->contains('user_id', $user_id);
|
|
}
|
|
}
|