Laravel Storage Delete Multiple Files Example
Hey Friends,
In this short guide, we will show you laravel storage delete multiple files. let’s discuss about how to remove multiple files in laravel storage. I’m going to show you about laravel store multiple images remove. This example will help you laravel storage remove multiple files. Alright, let us dive into the details.
Laravel Storage facade provides delete() method to remove multiple files from storage folder. so, let's see the simple example code.
let's see the example:
Example 1: Laravel Storage Delete Multiple Files
here is a controller code of delete multiple files using Storage facade.
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.');
}
}
Output:
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.');
}
}
}
Output:
File deleted successfully.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Get File Contents from Storage Example
- How to Migrate SQL File in Laravel Migration?
- How to Read Content from PDF File in Laravel?
- Laravel TCPDF: Generate HTML to PDF File Example
- Laravel Delete File After Download Response Example
- How to Check If Request Has File in Laravel?
- Laravel Download File from URL to Storage Example
- Laravel Blade Include File Example
- How to Delete File from Public Folder / Storage Folder in Laravel?
- How to Display Image from Storage Folder in Laravel?
- Laravel Vue JS File Upload Example
- How to Get File Extension from Path in Laravel?
- How to Get File Size from Storage in Laravel?
- Laravel Storage Dropbox Integration Example