我是在MYSQL中找取檔名, 以下是可正常運行,
但可否Storage::delete中指示刪除多個檔案,
請教一些比較簡潔寫法.
$deletePic123 = DB::table('db')->where('ID',$id)->get();
$PIC_PATH1 = $deletePic123[0]->PIC_PATH1;
$PIC_PATH2 = $deletePic123[0]->PIC_PATH2;
$PIC_PATH3 = $deletePic123[0]->PIC_PATH3;
Storage::delete('img/'.$PIC_PATH1);
Storage::delete('img/'.$PIC_PATH2);
Storage::delete('img/'.$PIC_PATH3);
謝謝各位大大
use Illuminate\Support\Facades\Storage;
Storage::delete('file.jpg');
Storage::delete(['file.jpg', 'file2.jpg']);
// 僅供參考
$deletePics = DB::table('db')
->where('ID', $id)
->get();
$picCount = 3;
foreach ($deletePics as $deletePic) {
for ($i = 1; $i <= $picCount; $i++) {
$column = 'PIC_PATH' . $i;
$path = $deletePic->{$column} ?? '';
($path !== '') && Storage::delete('img/' . $path);
}
}