Add AccountService

This commit is contained in:
Daniel Supernault 2019-11-22 22:34:56 -07:00
parent 5740746339
commit 885a1258e8
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -0,0 +1,29 @@
<?php
namespace App\Services;
use Cache;
use App\Profile;
use App\Transformer\Api\AccountTransformer;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
class AccountService {
const CACHE_KEY = 'pf:services:account:';
public static function get($id)
{
$key = self::CACHE_KEY . ':' . $id;
$ttl = now()->addHours(12);
return Cache::remember($key, $ttl, function() use($id) {
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$profile = Profile::whereNull('status')->findOrFail($id);
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
return $fractal->createData($resource)->toArray();
});
}
}