diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 60d74be..69a5faf 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -16,7 +16,6 @@ use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Storage; -// use Maatwebsite\Excel\Excel as ExcelType; use Maatwebsite\Excel\Facades\Excel; class UserController extends Controller @@ -143,21 +142,11 @@ class UserController extends Controller $disk = 'imports'; $filename = $file_users->store(path: "", options: $disk); - - // $mimeType = $file_users->getMimeType(); - // $type = match($mimeType) { - // "text/csv" => ExcelType::CSV, - // "application/vnd.oasis.opendocument.spreadsheet" => ExcelType::ODS, - // "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => ExcelType::XLSX, - // "application/vnd.ms-excel" => ExcelType::XLS, - // default => ExcelType::XLSX, - // }; Excel::import( import: new UsersWithSmartUsersImport($file_logos), filePath: $filename, disk: $disk, - // readerType: $type ); return response() @@ -166,7 +155,7 @@ class UserController extends Controller } catch (\Throwable $th) { throw $th; } finally { - Storage::disk($driver)->delete($filename); + Storage::disk($disk)->delete($filename); } } } diff --git a/app/Imports/UsersWithSmartUsersImport.php b/app/Imports/UsersWithSmartUsersImport.php index a0cf1e4..51b6699 100644 --- a/app/Imports/UsersWithSmartUsersImport.php +++ b/app/Imports/UsersWithSmartUsersImport.php @@ -4,12 +4,14 @@ namespace App\Imports; use App\Models\DadosCadastrais; use App\Models\User; + use Illuminate\Http\File; use Illuminate\Support\Str; use Illuminate\Http\UploadedFile; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Storage; + use Maatwebsite\Excel\Concerns\ToCollection; use ZanySoft\Zip\Facades\Zip; @@ -113,11 +115,12 @@ class UsersWithSmartUsersImport implements ToCollection $picture = new File($temp_file_path); $pathS3 = "avatars/{$picture->hashName()}"; + Storage::disk('s3')->missing($pathS3) && Storage::disk('s3')->put($pathS3, $picture->getContent()); $filename = \preg_replace("/\.[^\.]+$/", "", $filename); - $this->files_paths[$filename] = url('/images/test.png') ?? Storage::disk('s3')->url($pathS3); + $this->files_paths[$filename] = Storage::disk('s3')->url($pathS3); \unlink($temp_file_path); }); diff --git a/composer.json b/composer.json index b45b128..a73d701 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "@php artisan config:clear --ansi", "@php artisan schedule:clear-cache --ansi" ], - "authorized-files": "sudo chown -R www-data:www-data storage/ storage/framework/cache storage/framework/cache/data bootstrap/cache/ public/", + "authorized-files": "sudo chown -R www-data:www-data storage/ bootstrap/cache/ public/ && sudo chown -R :www-data storage/", "dev": "@php artisan serve --host=0.0.0.0 --port=8080 --ansi" }, "extra": {