<?php


namespace App\Traits;


trait ImageUpload
{
    public function uploadImage($imagepath, $image, $name = '')
    {
        if (!is_dir($imagepath))
        {
            mkdir($imagepath, 0755, true);
        }
        $imageName                          = $name.$image->getClientOriginalName();
        $image->move($imagepath,$imageName);
        return $imagepath.$imageName;
    }

    public function uploadImageUpdate($imagepath, $image, $name = '', $previousImage = '')
    {
        if (!is_dir($imagepath))
        {
            mkdir($imagepath, 0755, true);
        }
        @unlink($previousImage);
        $imageName                          = $name.$image->getClientOriginalName();
        $image->move($imagepath,$imageName);
        return $imagepath.$imageName;
    }
}
