<?php

namespace App\Traits;

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

/**
 * Trait UploadAble
 * @package App\Traits
 */
trait UploadAble
{
    /**
     * @param UploadedFile $uploadedFile
     * @param null $folder
     * @param string $disk
     * @param null $filename
     * @return false|string
     */
    public function uploadOne(UploadedFile $uploadedFile, $folder = null, string $disk = 'public', $filename = null)
    {
        $name = time().$uploadedFile->getClientOriginalName();

        return $uploadedFile->storeAs($folder, $name, $disk);
    }

    /**
     * @param null $path
     * @param string $disk
     */
    public function deleteOne($path = null, string $disk = 'public'): void
    {
        Storage::disk($disk)->delete($path);
    }
}
