<?php
namespace App\Traits;
use App\Traits\FileUploadTrait;
use App\Models\FileCategory;
use App\Models\FileStaging;
use Auth;
trait FileUploadTrait
{

    //public $fileUploadPath = "/opt/lampp/htdocs/redbeep_files";
    //  private $fileUploadPath = "/home/e8vc2jm55npk/public_html/treesha_realestate/public/treesha_files";
    //private $fileUploadPath = "/home/vwfp663en198/public_html/redbeep_files";
    private $fileUploadPath = "D:/xampp/htdocs/cretive_files";

    // private $fileBasePath = "https://treeshaeduvice.co/treesha_realestate/public/treesha_files/";
    //private $fileBasePath = "http://projectupdate.shop/laravel/public/treesha_files/";
    private $fileBasePath = "http://localhost/cretive_files/";

    public function getBasePath()
    {

        return $this->fileBasePath;
    }
    public function uploadFile($catId, $file)
    {

        $cat = FileCategory::find($catId);

        $model = new FileStaging;

        $model->original_name  = $file->getClientOriginalName();
        $model->mime_type      = $file->getClientMimeType();
        $model->file_cat_id    = $catId;
        $model->uploaded_by    = Auth::user()->id;
        $model->file_extension = $file->getClientOriginalExtension();
        $model->file_size      = $file->getSize();
        $model->save();

        $saveName = $cat->file_name_prefix . str_pad($model->id, 8, "0", STR_PAD_LEFT) . '_' . time() . '.' . $model->file_extension;
        $m        = $file->move($this->fileUploadPath, $saveName);

        $model->is_uploaded = true;
        $model->upload_name = $saveName;
        $model->save();

        return $saveName;
    }

}
