123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Giveaway extends Model
- {
- protected $table = 'giveaway';
- protected $fillable = [
- 'user_id','purchaser_user_id','title','amount','order_id','created_at','updated_at'
- ];
- public function user()
- {
- return $this->hasOne(User::class, 'id', 'purchaser_user_id')->select(['id', 'name', 'avatar']);
- }
- public function buyUser()
- {
- return $this->hasOne(User::class, 'id', 'user_id')->select(['id', 'name', 'avatar']);
- } public function order()
- {
- return $this->hasOne(Order::class, 'id', 'order_id');
- }
- public function getAmountAttribute($value)
- {
- return $value / 100;
- }
- 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;
- }
- }
|