Created
February 17, 2022 20:00
Laravel + Media Library code to migrate files from local filesystem to AWS S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Spatie\MediaLibrary\Models\Media; | |
class MigrateFiles extends Command | |
{ | |
protected $signature = 'migrate-files'; | |
public function handle() | |
{ | |
$medias = Media::where('disk', 'public')->limit(5)->get(); | |
$bar = $this->output->createProgressBar(count($medias)); | |
$bar->start(); | |
foreach ($medias as $Media) { | |
$Model = $Media->model; | |
$Media->move($Model, $Media->collection_name, 's3'); | |
$bar->advance(); | |
} | |
$bar->finish(); | |
print "\n"; | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment