2022-12-20 16:00:49 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
|
|
|
trait Updates
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* get the path by alias.
|
|
|
|
*/
|
|
|
|
public function getPathByAlias(string $alias = ''): string
|
|
|
|
{
|
|
|
|
if (empty($alias)) {
|
|
|
|
$const = static::class . '::ALIAS';
|
|
|
|
|
|
|
|
$alias = defined($const) ? constant($const) : 'core';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $alias === 'core' ? base_path() : module_path($alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete the files.
|
|
|
|
*/
|
2023-01-17 15:00:00 +03:00
|
|
|
public function deleteFiles(array $files, $alias = ''): void
|
2022-12-20 16:00:49 +03:00
|
|
|
{
|
|
|
|
$path = $this->getPathByAlias($alias);
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
File::delete($path . '/' . $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete the folders.
|
|
|
|
*/
|
2023-01-17 15:00:00 +03:00
|
|
|
public function deleteFolders(array $folders, $alias = ''): void
|
2022-12-20 16:00:49 +03:00
|
|
|
{
|
|
|
|
$path = $this->getPathByAlias($alias);
|
|
|
|
|
|
|
|
foreach ($folders as $folder) {
|
|
|
|
File::deleteDirectory($path . '/' . $folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|