composer require league/flysystem-aws-s3-v3 Go to your app filesystem and added s3 storage ‘s3’ => [‘driver’ => ‘s3’,‘key’ => env(‘AWS_KEY’),‘secret’ => env(‘AWS_SECRET’),‘region’ => env(‘AWS_REGION’),‘bucket’ => env(‘AWS_BUCKET’),‘url’ => env(‘AWS_URL’),‘visibility’ => ‘public’,], 5.

Update the code below into S3 Controller public function UploadImagesToAwsS3(){$posts = {Query to fetch images from db table}if (sizeof($posts) > 0){$moved_count = 0;$error_count = 0;foreach ($posts as $post){if ($post->image && file_exists({image_url}){//this code will upload images to S3 Storage$moved = Storage::disk(‘s3’)->put({image_name}, file_get_contents({image_url}));if ($moved){$moved_count++;//update S3 url into the table$update ={model_name}::findOrFail($post->id);//asw flag$update->aws = ‘1’;//asw url$update->aws_path = ‘https://'.env('AWS_BUCKET').'.s3.'.env('AWS_REGION').'.amazonaws.com/'. image_name};$update->update();}else{$error_count++;}}}return $moved_count.’ images are moved to amazon S3 storage successfully and ‘.$error_count.’ images are failed to move’;}else{return “No images are available to move”;}} That’s it, now just run the route URL into the URL application to upload the images to S3 Storage.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners