db); Document::whereIn('id', $this->document_ids) ->where('company_id', $this->entity->company_id) ->each(function ($document) { $file = $document->getFile(); $extension = pathinfo($document->name, PATHINFO_EXTENSION); $new_hash = \Illuminate\Support\Str::random(32) . "." . $extension; Storage::disk($document->disk)->put( "{$this->entity->company->company_key}/documents/{$new_hash}", $file, ); $instance = Storage::disk($document->disk)->path("{$this->entity->company->company_key}/documents/{$new_hash}"); $new_doc = new Document(); $new_doc->user_id = $this->entity->user_id; $new_doc->company_id = $this->entity->company_id; $new_doc->url = $instance; $new_doc->name = $document->name; $new_doc->type = $extension; $new_doc->disk = $document->disk; $new_doc->hash = $new_hash; $new_doc->size = $document->size; $new_doc->width = $document->width; $new_doc->height = $document->height; $new_doc->is_public = $document->is_public; $this->entity->documents()->save($new_doc); }); } }