<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Share extends Model
{
    protected $fillable = ['user_id', 'pid', 'diamond', 'created_at', 'updated_at','desc'];

    protected $table = 'share';

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'pid')->select(['id', 'name', 'avatar']);
    }
    public function inviteData()
    {
        return $this->hasOne(User::class, 'id', 'user_id')->select(['id', 'name', 'avatar']);
    }
    public function pidData()
    {
        return $this->hasOne(User::class, 'id', 'pid')->select(['id', 'name', 'avatar']);
    }
    public function getCreatedAtAttribute($value)
    {
        $dateTime = new \DateTime($value);

        // 格式化时间
        $formattedTime = $dateTime->format('Y-m-d H:i:s');

        return $formattedTime;
    }

    public function getUpdatedAtAttribute($value)
    {
        $dateTime = new \DateTime($value);

        // 格式化时间
        $formattedTime = $dateTime->format('Y-m-d H:i:s');

        return $formattedTime;
    }
}
