| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Module\Friend\Models;
- use UCore\ModelCore;
- use App\Module\User\Models\User;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 好友关系模型
- *
- * 该模型用于表示用户之间的好友关系,包含好友基本信息、关系状态等。
- * field start
- * @property int $id 主键ID
- * @property int $user_id 用户ID
- * @property int $friend_id 好友ID
- * @property string $remark 好友备注名
- * @property int $group_id 好友分组ID
- * @property int $intimacy 亲密度
- * @property int $status 状态:1正常,2特别关注,3黑名单
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- *
- * @property-read User $user 用户关联
- * @property-read User $friend 好友关联
- */
- class FriendRelation extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'friend_relations';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'friend_id',
- 'remark',
- 'group_id',
- 'intimacy',
- 'status',
- ];
- // attrlist end
- /**
- * 属性默认值
- *
- * @var array
- */
- protected $attributes = [
- 'group_id' => 0,
- 'intimacy' => 0,
- 'status' => 1,
- ];
- /**
- * 属性类型转换
- *
- * @var array
- */
- protected $casts = [
- 'user_id' => 'integer',
- 'friend_id' => 'integer',
- 'group_id' => 'integer',
- 'intimacy' => 'integer',
- 'status' => 'integer',
- ];
- /**
- * 获取关联的用户
- *
- * @return BelongsTo
- */
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class, 'user_id');
- }
- /**
- * 获取关联的好友
- *
- * @return BelongsTo
- */
- public function friend(): BelongsTo
- {
- return $this->belongsTo(User::class, 'friend_id');
- }
- }
|