I want to delete a file that is stored in storage/app/myfolder/file.jpg. I have tried the following codes but none of this works:
use File
$file_path = u
For example update customer profile image and remove old image
Stored file in database ($customer->image)
/storage/customers/mhPKW870zGFupAZLI5cwNLoHTAuguCQWoBrDXJCU.jpeg
Update method
if ($request->file('image')) {
if ($customer->image) {
// get filename
$filename = str_replace('/storage/customers/', '', $customer->image);
// remove old image
unlink(storage_path('app/public/customers/'.$filename));
}
// add new image
$path = Storage::putFile('public/customers', $request->file('image'));
$url = Storage::url($path);
$customer->image = $url;
}
$saveResult = $customer->save();