Changing Laravel’s default path for S3 uploads

Recently, I was working with Spatie‘s media library package which allows you to associate models with files and everything worked as in the docs but it was generating URLs for my media files of this sort:

and I wanted it to be like this:

so I first I figured there must be something wrong with the custom path generator I created but it turns out that Laravel controls that part of the URL through the disk options in “/config/filesystems.php”. So, I have a media disk there, that looks like this

'media' => [
  'driver' => 's3', 
  'root' => 'uploads/', // <- NOTICE THIS LINE it used to be public_path('media')
  'url' => env('AWS_S3_URL').'media', 
  'key' => env('AWS_ACCESS_KEY_ID'), 
  'secret' => env('AWS_SECRET_ACCESS_KEY'), 
  'region' => env('AWS_DEFAULT_REGION'), 
  'bucket' => env('AWS_BUCKET'), 
  'url' => env('AWS_URL'), 
  'endpoint' => env('AWS_ENDPOINT'), 
  'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 

notice the ‘root’ => ‘uploads/’ that part controls the first part of the S3 upload URL’s path.