// Import the Filesystem class use Illuminate\Filesystem\Filesystem; // Initialize the Filesystem class instance $filesystem = new Filesystem; // Delete the directory and all its contents $filesystem->deleteDirectory('/path/to/directory');
// Delete the directory and all its contents including hidden files $filesystem->deleteDirectory('/path/to/directory', true);In this example, we pass a second argument as `true` to the `deleteDirectory` method. This will delete the directory and all its contents, including hidden files. In conclusion, the `deleteDirectory` method of the `Filesystem` class in the `illuminate/filesystem` package library is an efficient method for deleting a directory and all of its contents recursively.