LARAVEL 清空某文件夹下的所有文件 修改env配置文件
LARAVEL 清空某文件夹下的所有文件
$file = new Filesystem;
$file->cleanDirectory('bootstrap/cache');
代码修改env配置文件
$data=[
'BAN_STATUS'=>'false',
'PASSPORT_CLIENT'=>1,
];
public function updateEnv(array $data)
{
$envPath = base_path() . DIRECTORY_SEPARATOR . '.env';
$contentArray = collect(file($envPath, FILE_IGNORE_NEW_LINES));
$contentArray->transform(function ($item) use ($data){
foreach ($data as $key => $value){
if(str_contains($item, $key)){
return $key . '=' . $value;
}
}
return $item;
});
$content = implode("\n", $contentArray->toArray());
\File::put($envPath, $content);
}
:+1: