开发者社区> 问答> 正文

如何在Laravel Eloquent中删除带有图像的多个文本

我试图使用以下代码从MySQL数据库中永久删除文本和图像,但是我花了将近一天的时间不知道自己在做什么错,请帮忙。

{
    if ($request->isMethod("post")) {
        $data = $request->all();
        // $postDelete=Post::where('id' ,'>' ,0)->pluck('id')->toArray();
        $postDeletes = Post::where('id', '>', 0)->get('post_image');

        foreach ($postDeletes as $postDelete) {
            # code...

            # code...
            // $postDeletes=Post::where(['id'=> $id])->get();
            //}
            $large_image_paths = 'images/backend_image/admin_users/small/';
            $medium_image_paths = 'images/backend_image/admin_users/medium/';
            $small_image_paths = 'images/backend_image/admin_users/large/';

            // Delete Image permenently from product table begins, Delete Large image if not exist
            if (file_exists($large_image_paths.$postDelete->post_image)) {
                unlink($large_image_paths.$postDelete->post_image);
            }

            // Delete Large image if not exist
            if (file_exists($small_image_paths.$postDelete->post_image)) {
                unlink($small_image_paths.$postDelete->post_image);
            }

            // Delete Medium image if not exist
            if (file_exists($medium_image_paths.$postDelete->post_image)) {

                unlink($medium_image_paths.$postDelete->post_image);
            }
        }

        //$del_id=$request->input('del_feedback');
        Post::whereIn('id', $data['del_user'])->delete();

        return redirect()->back()->with("flash_message_success", "you Successfully Deleted The Selected Users(s)");
    }
}

展开
收起
社区秘书 2019-12-09 16:58:03 468 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载