|
@@ -15,7 +15,7 @@ class AccountService
|
|
{
|
|
{
|
|
const CACHE_KEY = 'pf:services:account:';
|
|
const CACHE_KEY = 'pf:services:account:';
|
|
|
|
|
|
- public static function get($id)
|
|
|
|
|
|
+ public static function get($id, $softFail = false)
|
|
{
|
|
{
|
|
if($id > PHP_INT_MAX || $id < 1) {
|
|
if($id > PHP_INT_MAX || $id < 1) {
|
|
return [];
|
|
return [];
|
|
@@ -24,10 +24,16 @@ class AccountService
|
|
$key = self::CACHE_KEY . $id;
|
|
$key = self::CACHE_KEY . $id;
|
|
$ttl = now()->addHours(12);
|
|
$ttl = now()->addHours(12);
|
|
|
|
|
|
- return Cache::remember($key, $ttl, function() use($id) {
|
|
|
|
|
|
+ return Cache::remember($key, $ttl, function() use($id, $softFail) {
|
|
$fractal = new Fractal\Manager();
|
|
$fractal = new Fractal\Manager();
|
|
$fractal->setSerializer(new ArraySerializer());
|
|
$fractal->setSerializer(new ArraySerializer());
|
|
- $profile = Profile::findOrFail($id);
|
|
|
|
|
|
+ $profile = Profile::find($id);
|
|
|
|
+ if(!$profile) {
|
|
|
|
+ if($softFail) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ abort(404);
|
|
|
|
+ }
|
|
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
|
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
|
return $fractal->createData($resource)->toArray();
|
|
return $fractal->createData($resource)->toArray();
|
|
});
|
|
});
|