How to delete files from the public folder in laravel?

I am building a blog website with Laravel. Right now I can create, edit and delete posts. But the problem is when I delete the post, it deletes from the database but the thumbnail image remains in the public folder.
how do I delete the image from the public folder?
Here is my delete function.

 public function destroy($id) {
    $post       = Post::findOrFail($id);
   
    // Delete the thumbnail
    // $thumbnail  = public_path("uploads/{$post->thumbnail}");

    $post->delete();
    return redirect('admin/posts')->with('message', 'Post deleted successfully!');
}

To delete files from the public folder, you can use the default PHP unlink function.

unlink($thumbnail);

Or you can use Laravel File::delete function.

File::delete($thumbnail);

You need to add the line at the top of your file else the File class will be undefined.

use Illuminate\Support\Facades\File;

Now your complete function should look like this.

 public function destroy($id) {
    $post       = Post::findOrFail($id);
   
    // Delete the thumbnail
    $thumbnail  = public_path("uploads/{$post->thumbnail}");
    if (File::exists($thumbnail)) { 
        File::delete($thumbnail); 
    }

    $post->delete();
    return redirect('admin/posts')->with('message', 'Post deleted successfully!');
}

If you want to delete multiple files at once, you can pass multiple param or an array to the function.

File::delete($thumbnail1, $thumbnail2, $thumbnail3);
// or
$thumbnails = array($thumbnail1, $thumbnail2, $thumbnail3);
File::delete($thumbnails);