此功能删除品牌但照片仍保存在public/upload/brands/文件夹中
我想删除它时也会从文件夹中删除照片。
public function deleteBrand($request){
$deletelogo = $this->brandyModel::where('id',$request->id)->first();
$logo = $deletelogo->logo;
if (is_file($logo)){
unlink(public_path('upload/brands'.$logo));
}
$deletelogo->delete();
$notificat = array(
'message' => 'Brand Deleted Successfully',
'alert-type' => 'success',
);
return redirect()->back()->with($notificat);
}
答案 0 :(得分:0)
我认为只是打字错误,让我重构您的代码
public function deleteBrand($request){
$deletelogo = $this->brandyModel::where('id',$request->id)->first();
$logo = $deletelogo->logo;
$url = public_path('view/upload/brands/'.$logo); // Take a look at this Url, you might wanna change it
if (file_exists($url)){
unlink($url);
}
$deletelogo->delete();
$notificat = array(
'message' => 'Brand Deleted Successfully',
'alert-type' => 'success',
);
return redirect()->back()->with($notificat);
答案 1 :(得分:0)
感谢所有尝试帮助。我解决了它路径应该在“”之间,
喜欢这段代码,现在效果很好,
f(return_const())