We will demonstrate how to delete numerous files from Laravel storage in this little post. Let’s talk about how to delete several files from a Laravel storage location. I’ll demonstrate how to remove numerous photos from a Laravel store. You may remove numerous files using laravel storage by using this example. Okay, let’s get into the specifics.
To remove numerous files from a storage folder, use the delete() method provided by the Laravel Storage facade. let’s examine the straightforward example code.
let’s see the example:
Example 1: Laravel Storage Delete Multiple Files
app/Http/Controllers/FileController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use File;
class FileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
Storage::delete(['upload/test.txt', 'upload/test2.txt', 'upload/test3.txt']);
dd('Files deleted successfully.');
}
}
Example 2: Laravel Storage Delete File If Exists
here is a controller code of delete file using Storage facade.
app/Http/Controllers/FileController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class FileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if(Storage::exists('upload/test.txt')){
Storage::delete('upload/test.txt');
dd('File deleted successfully.');
}else{
dd('File does not exist.');
}
}
}
I’m Abhishek, a DevOps, SRE, DevSecOps, and Cloud expert with a passion for sharing knowledge and real-world experiences. I’ve had the opportunity to work with Cotocus and continue to contribute to multiple platforms where I share insights across different domains:
-
DevOps School – Tech blogs and tutorials
-
Holiday Landmark – Travel stories and guides
-
Stocks Mantra – Stock market strategies and tips
-
My Medic Plus – Health and fitness guidance
-
TrueReviewNow – Honest product reviews
-
Wizbrand – SEO and digital tools for businesses
I’m also exploring the fascinating world of Quantum Computing.