瀏覽代碼

Add ProfileService

Daniel Supernault 6 年之前
父節點
當前提交
896012bcaa
共有 1 個文件被更改,包括 43 次插入0 次删除
  1. 43 0
      app/Services/ProfileService.php

+ 43 - 0
app/Services/ProfileService.php

@@ -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;
+		});
+	}
+
+}