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

shadrix's avatar
Level 12

How do I move my images to s3 in production and in development let it stay locally?

I have read this thread, however I'm still not really sure how to handle this.

Of course, I could set FILESYSTEM_DRIVER to s3, but this won't really work.

Let me explain:

If we upload a simple avatar file:

request()
        ->file('avatar')
        ->store('avatars', 'public')

The file is saved in the DB for example: avatars/R6ZGC9U0c22mKMcAADZbc8kJeU8soTvOuNFvnYgv.jpeg

This file is stored in the local public storage file. However, if we now want to change the default filesystem to S3, nothing is going to change obviously.

Now, this is going to be even harder, when we fetch the image via the assetmethod. Usually, I just need to write:

 public function getAvatarAttribute($avatar)
{
    return asset('storage/' . $avatar));
}

to get the avatar file (because of the symlink in the public folder).

What now? I obviously don't save a storage folder.

How would you handle this?

0 likes
1 reply
Sinnbeck's avatar

You could change the asset url. The laravel documentation says the following

You can configure the asset URL host by setting the ASSET_URL variable in your .env file. This can be useful if you host your assets on an external service like Amazon S3:

// ASSET_URL=http://example.com/assets

$url = asset('img/photo.jpg'); // http://example.com/assets/img/photo.jpg

https://laravel.com/docs/5.8/helpers#method-asset

1 like

Please or to participate in this conversation.