Cao.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. use Illuminate\Notifications\Notifiable;
  6. use Laravel\Sanctum\HasApiTokens;
  7. /**
  8. * Admin
  9. * @mixin Builder
  10. * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
  11. */
  12. class Cao extends Authenticatable
  13. {
  14. use HasApiTokens, Notifiable;
  15. protected $table = 'cao';
  16. protected $hidden = ['created_at', 'updated_at'];
  17. protected $fillable = ['field', 'val'];
  18. static function updateData(array $awards)
  19. {
  20. foreach ($awards as $field) {
  21. $cao = static::where('field', $field)->first();
  22. if (!$cao) {
  23. $cao = new Cao();
  24. $cao->field = $field;
  25. $cao->save();
  26. }
  27. $cao->increment('val');
  28. }
  29. }
  30. protected function getCreatedAtAttribute($value)
  31. {
  32. return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
  33. }
  34. protected function getUpdatedAtAttribute($value)
  35. {
  36. return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
  37. }
  38. }