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:
parent
df96b800c4
commit
2e8fb762ae
1 changed files with 5 additions and 3 deletions
|
@ -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));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue