1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Services/ProfileService.php

33 lines
772 B
PHP
Raw Normal View History

2019-02-14 21:23:33 +00:00
<?php
namespace App\Services;
2019-12-11 06:04:03 +00:00
use Cache;
use Illuminate\Support\Facades\Redis;
use App\Transformer\Api\AccountTransformer;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Profile;
2019-02-14 21:23:33 +00:00
class ProfileService {
public static function get($id)
2019-02-14 21:23:33 +00:00
{
$key = 'profile:model:' . $id;
$ttl = now()->addHours(4);
$res = Cache::remember($key, $ttl, function() use($id) {
$profile = Profile::find($id);
if(!$profile) {
return false;
}
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
return $fractal->createData($resource)->toArray();
2019-02-14 21:23:33 +00:00
});
return $res;
2019-02-14 21:23:33 +00:00
}
}