Share.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Share extends Model
  5. {
  6. protected $fillable = ['user_id', 'pid', 'diamond', 'created_at', 'updated_at', 'desc'];
  7. protected $table = 'share';
  8. public function user()
  9. {
  10. return $this->hasOne(User::class, 'id', 'pid')->select(['id', 'name', 'avatar']);
  11. }
  12. public function inviteData()
  13. {
  14. return $this->hasOne(User::class, 'id', 'user_id')->select(['id', 'name', 'avatar']);
  15. }
  16. public function pidData()
  17. {
  18. return $this->hasOne(User::class, 'id', 'pid')->select(['id', 'name', 'avatar']);
  19. }
  20. public function getCreatedAtAttribute($value)
  21. {
  22. $dateTime = new \DateTime($value);
  23. // 格式化时间
  24. $formattedTime = $dateTime->format('Y-m-d H:i:s');
  25. return $formattedTime;
  26. }
  27. public function getUpdatedAtAttribute($value)
  28. {
  29. $dateTime = new \DateTime($value);
  30. // 格式化时间
  31. $formattedTime = $dateTime->format('Y-m-d H:i:s');
  32. return $formattedTime;
  33. }
  34. }