Generate multiple avatar sizes for better performance loading and frugal traffic

This commit is contained in:
Čarodej
2021-11-03 16:28:14 +01:00
parent dc8ec5f20b
commit f139dbae08
30 changed files with 280 additions and 152 deletions

View File

@@ -20,16 +20,23 @@ class UserSettings extends Model
*/
public function getAvatarAttribute()
{
$link = [];
// Get avatar from external storage
if ($this->attributes['avatar'] && ! is_storage_driver('local')) {
return Storage::temporaryUrl($this->attributes['avatar'], now()->addDay());
foreach (config('vuefilemanager.avatar_sizes') as $item) {
$filePath = "avatars/{$item['name']}-{$this->attributes['avatar']}";
$link[$item['name']] = Storage::temporaryUrl($filePath, now()->addDay());
}
return $link;
}
// Get avatar from local storage
if ($this->attributes['avatar']) {
$link = [];
foreach (config('vuefilemanager.avatar_sizes') as $item) {
$link[$item['name']] = url("/avatars/{$item['name']}-{$this->attributes['avatar']}");
}