Company.php 809 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Model;
  5. use Carbon\Carbon;
  6. use Illuminate\Support\Facades\Cache;
  7. class Company extends Model
  8. {
  9. /**
  10. * @var string
  11. */
  12. protected $table = 'base_departments';
  13. protected $guarded = [];
  14. /**
  15. * The attributes excluded from the model's JSON form.
  16. *
  17. * @var array
  18. */
  19. protected $hidden = [];
  20. /***
  21. * 根据id获取对象
  22. * @param $id
  23. * @return mixed
  24. */
  25. public static function byId($id)
  26. {
  27. return Cache::remember('model:company:byId:' . $id, Carbon::now()->addDays(1), function () use ($id) {
  28. return self::query()->where('id', $id)->where('status', ModelStatusEnum::OK)->first();
  29. });
  30. }
  31. }