1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?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;
- }
- }
|