当我尝试从db删除图像时出现此错误: 未定义的变量:removeslider
public function delete($id){
$getslider = DB::table('slider')->where('id',$id)->get();
foreach($getslider as $getslider) {
$removeslider = $getslider->bgimage;
}
Storage::disk('uploadssliders')->delete($removeslider);
return redirect('admin/inicio');
}
答案 0 :(得分:1)
尝试一下:
public function delete($id)
{
$getslider = DB::table('slider')->where('id',$id)->first();
if($getslider){
Storage::disk('uploadssliders')->delete($getslider->bgimage);
return redirect('admin/inicio');
} else {
//id has no match in the database
echo "the id ". $id . " does not exist";
}
}
我将您的get()
更改为first()
只能得到一个结果,因为这似乎是您要尝试执行的操作,因此不需要foreach
。