Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

motinska94's avatar

Is there a way to return back without using cached images?

My client wanted me to add a function to rotate images on the site. It's working just fine on my pc but it doesn't show on the server immediately. It only rotates the image after I do Ctrl + F5 I'm guessing it's because images are cached on the server side. Is there a way to prevent that and un-cache all images when redirecting back to the page after the rotation?

As I said it's working fine on my pc, which means I'm not caching any images on my side, it's probably the server doing this. Since it's a control panel that doesn't need to be speedy, I can take something to replicate a Ctrl + F5 hotkey too.

Idk if that matters but here's my function to rotate (using intervention library):

    public function flip_photo(Request $request, EstatesPhoto $estatesPhoto)
    {
        $img_path = $estatesPhoto->path;
        $request->input('rotation') == 'left' ? $rotation = 90 : $rotation = -90;

        $image = Image::make($img_path);
        $image->rotate($rotation);
        
        unlink(public_path($img_path));
        $image->save($img_path);
        return back();
    }
0 likes
5 replies
Sinnbeck's avatar

Show how you are adding them to page. Sounds like you are missing a hash/version value

1 like
motinska94's avatar

@Sinnbeck I don't understand what you mean by adding them to the page but if this is what you're asking, I'm using good ol foreach + img src with image path. Was I supposed to do something else?

@foreach($estate->images as $image)
    <img src="{{ asset($image->path) }}" class="estate-image-element">
@endforeach
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@motinska94 yes that's exactly it. If the name of the file remains the same, the browser will show the same again (from cache). You need to either make sure the file names are unique or add a version as a parameter

Just an example if the image has a hash method. It could be the timestamp of when the file was created

@foreach($estate->images as $image)
    <img src="{{ asset($image->path) }}?version={{$image->hash}}" class="estate-image-element">
@endforeach
motinska94's avatar

@Sinnbeck Wow that's really smart, thanks! I tried adding ?date= {{$image->updated_at}} but didn't work, I guess I can rename the file though, it shouldn't be a problem. Thanks a lot!

Please or to participate in this conversation.