faithgen /
laravel-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace FaithGen\SDK\Traits; |
||
| 4 | |||
| 5 | use Illuminate\Support\Facades\Log; |
||
| 6 | use Illuminate\Support\Facades\Storage; |
||
| 7 | use Illuminate\Support\Str; |
||
| 8 | use InvalidArgumentException; |
||
| 9 | |||
| 10 | trait SavesToAmazonS3 |
||
| 11 | { |
||
| 12 | use FileTraits; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Saves model images to Amazon s3. |
||
| 16 | * |
||
| 17 | * @param $model |
||
| 18 | */ |
||
| 19 | protected function saveFiles($model) |
||
| 20 | { |
||
| 21 | if (! in_array(StorageTrait::class, class_uses($model))) { |
||
| 22 | throw new InvalidArgumentException('The model you used does not use the Storage trait'); |
||
| 23 | } |
||
| 24 | |||
| 25 | try { |
||
| 26 | foreach ($model->images as $image) { |
||
| 27 | $imageFiles = $this->getImages($model->filesDir(), $image->name, $model->getImageDimensions()); |
||
| 28 | |||
| 29 | foreach ($imageFiles as $imageFile) { |
||
| 30 | Storage::disk('s3')->put(Str::of($imageFile)->after('public/'), fopen($imageFile, 'r+'), 'public'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 31 | } |
||
| 32 | } |
||
| 33 | $this->deleteFiles($model); |
||
| 34 | } catch (\Exception $e) { |
||
| 35 | Log::error($e->getMessage()); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 |