Add ProfileService
This commit is contained in:
parent
705d4ef942
commit
896012bcaa
1 changed files with 43 additions and 0 deletions
43
app/Services/ProfileService.php
Normal file
43
app/Services/ProfileService.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Cache, Redis;
|
||||
|
||||
use App\{
|
||||
Follower,
|
||||
Profile
|
||||
};
|
||||
|
||||
class ProfileService {
|
||||
|
||||
protected $profile;
|
||||
protected $profile_prefix;
|
||||
|
||||
public static function build()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function profile(Profile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->profile_prefix = 'profile:model:'.$profile->id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function profileId($id)
|
||||
{
|
||||
return Cache::rememberForever('profile:model:'.$id, function() use($id) {
|
||||
return Profile::findOrFail($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return Cache::rememberForever($this->profile_prefix, function() {
|
||||
return $this->profile;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue