Viewing file: CustomFileTrait.php (927 B) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Traits;
use Carbon\Carbon; use Illuminate\Support\Facades\File; use Illuminate\Support\Str;
trait CustomFileTrait {
public function createDirectory($path) { if(!File::isDirectory($path)) { File::makeDirectory($path, 0777, true, true); } }
public function saveCustomFileAndGetImageName($image,$path) { $rand_key=Str::random(12); $newImageName = time().$rand_key.$image->getClientOriginalName(); $image->move($path, $newImageName); return $newImageName; }
public function removeOldImage($image,$path) { if($image) { $oldImage = $path.'/'.$image; if (File::exists($oldImage)) { unlink($oldImage); } }
}
public function changeDateFormat($date,$fromFormat,$toFormat) { return Carbon::createFromFormat($fromFormat,$date)->format($toFormat); } }
|