1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-23 00:05:29 +00:00

Update Profile model, improve #381

This commit is contained in:
Daniel Supernault 2018-08-15 18:21:42 -06:00
parent df96b800c4
commit 2e8fb762ae
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -125,14 +125,16 @@ class Profile extends Model
public function avatar()
{
return $this->hasOne(Avatar::class);
return $this->hasOne(Avatar::class)->withDefault([
'media_path' => 'public/avatars/default.png'
]);
}
public function avatarUrl()
{
$url = Cache::remember("avatar:{$this->id}", 1440, function() {
$path = $this->avatar->media_path ?? 'public/avatars/default.png';
$version = $this->avatar ? hash('sha1', $this->avatar->created_at) : '';
$path = optional($this->avatar)->media_path;
$version = hash('sha1', $this->avatar->created_at);
$path = "{$path}?v={$version}";
return url(Storage::url($path));
});