Skip to content

Commit

Permalink
Add AccountService
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Nov 23, 2019
1 parent 5740746 commit 885a125
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/Services/AccountService.php
@@ -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();
});
}

}

0 comments on commit 885a125

Please sign in to comment.