目录为空,但 laravel 不会删除它,抛出 "It is not empty" 的错误

Directory is empty but laravel does not erase it, throwing the error that "It is not empty"

我正在尝试删除很多已经为空的特定条件的目录:

$noticias = Noticia::where('id_idioma', '2')->get();

    foreach($noticias as $noticia){

        $id = $noticia->id;
        $dirPath='images/noticias/'.$id.'/';
        rmdir($dirPath);

    }

这给我错误: ErrorException: rmdir(images/noticias/10446/): 目录不为空 但是目录是空的,知道吗?我还尝试删除 $dirPath 中的最后一个“/”。

我已经解决了使用 File::deletedirectory($dirPath) 而不是 rmdir($dirPath) 所以:

$noticias = Noticia::where('id_idioma', '2')->get();

foreach($noticias as $noticia){

    $id = $noticia->id;
    $dirPath='images/noticias/'.$id.'/';
    File::deletedirectory($dirPath);

}

不要忘记添加:use Illuminate\Support\Facades\File;