I'm working on a project where the users have to upload several images (through single form field) to a server. Using foreach
, I'm storing the images using ftp. Here's my code:
use Storage;
$image_list = $request->file('images');
foreach($image_list as $image){
$filename = Cuid::slug().'.'.$image->getClientOriginalExtension();
$path = "images/templates/";
Storage::disk('ftp')->put($path.$filename, 'Contents');
}
This code actually works fine but I'm afraid using storage facade directly like this can create several instances for every loop and It's not optimised code anymore. I tried creating an object for storage facade like this:
$storage = new Storage;
foreach($image_list as $image){
...
$storage->disk('ftp')->put($path.$filename, 'Contents');
}
But this gives me an error saying:
Call to undefined method Illuminate\Support\Facades\Storage::disk()
Is there any way not to call Storage facade directly every time the loop runs?