Bust avatar/banner cache so new image shows on all pages
After my previous fix the upload succeeds, but the avatar path is always .../profile/avatar.<ext>, so its media URL never changes. Pages other than the channel (which cache-busts with ?t=) kept serving the browser-cached OLD image — the user "still saw the old avatar" on /videos. - avatar_url / banner_url accessors append ?v=<updated_at timestamp>. - updateAvatar / updateBanner now bump updated_at explicitly (the path is unchanged, so Eloquent wouldn't otherwise touch it), changing ?v so every page fetches the new image. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
5d4d21dcec
commit
8ea63a6720
2 files changed
+15
-4
No files matched your search
+5
-2
@@ -162,7 +162,10 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function getAvatarUrlAttribute(): string
|
||||
{
|
||||
if ($this->avatar) {
|
||||
return route('media.avatar', $this->avatar);
|
||||
// ?v busts the browser cache when the avatar is replaced. The path is
|
||||
// always .../profile/avatar.<ext>, so without a version every page would
|
||||
// keep showing the previously cached image after an upload.
|
||||
return route('media.avatar', $this->avatar).'?v='.($this->updated_at?->timestamp ?? '0');
|
||||
}
|
||||
|
||||
return 'https://i.pravatar.cc/150?u='.$this->id;
|
||||
@@ -171,7 +174,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function getBannerUrlAttribute(): ?string
|
||||
{
|
||||
if ($this->banner) {
|
||||
return route('media.banner', $this->banner);
|
||||
return route('media.banner', $this->banner).'?v='.($this->updated_at?->timestamp ?? '0');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user