I'm trying to figure out what this bit of code does and why. This is a method to assist with an image upload process using the Intervention Image package. Whats really getting me is that the image path is getting saved to the DB but the image isn't getting saved to the file path.
Here is the part that seems to not be doing its part. I dont understand what the ->put($imageFileName, $resized->__toString(), 'public'); is doing, mostly the $resized->__toString() part.
// Calling the intervention Image package to resize image
$resized = Image::make($image)->resize(640, null, function ($constraint) {
$constraint->aspectRatio();
})->stream();
$resized_thumb = Image::make($image)->resize(320, 213)->stream();
$image_name = strtolower(time().Str::random(5).'-'.Str::slug($file_base_name)).'.' . $image->getClientOriginalExtension();
$imageFileName = 'uploads/images/'.$image_name;
$imageThumbName = 'uploads/images/thumbs/'.$image_name;
try{
//Upload original image to folder
$is_uploaded = current_disk()->put($imageFileName, $resized->__toString(), 'public');
if ($is_uploaded) {
//Save image name into db
$created_img_db = Media::create(['user_id' => $user_id, 'ad_id' => $ad_id, 'media_name'=>$image_name, 'type'=>'image', 'storage' => get_option('default_storage'), 'ref'=>'ad']);
//upload thumb image
current_disk()->put($imageThumbName, $resized_thumb->__toString(), 'public');
$img_url = media_url($created_img_db, false);
}
} catch (\Exception $e){
return redirect()->back()->withInput($request->input())->with('error', $e->getMessage()) ;
}
Here is the current disk method
// Set the current disk location for image uploads
function current_disk(){
$current_disk = \Illuminate\Support\Facades\Storage::disk('Default storage');
return $current_disk;
}