ProfileService.php 690 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Services;
  3. use Cache;
  4. use Illuminate\Support\Facades\Redis;
  5. use App\{
  6. Follower,
  7. Profile
  8. };
  9. class ProfileService {
  10. protected $profile;
  11. protected $profile_prefix;
  12. public static function build()
  13. {
  14. return new self();
  15. }
  16. public function profile(Profile $profile)
  17. {
  18. $this->profile = $profile;
  19. $this->profile_prefix = 'profile:model:'.$profile->id;
  20. return $this;
  21. }
  22. public function profileId($id)
  23. {
  24. return Cache::rememberForever('profile:model:'.$id, function() use($id) {
  25. return Profile::findOrFail($id);
  26. });
  27. }
  28. public function get()
  29. {
  30. return Cache::rememberForever($this->profile_prefix, function() {
  31. return $this->profile;
  32. });
  33. }
  34. }