我想编辑图片,但是不起作用。编辑图片的语法是什么?

我在控制器中尝试了以下方法:

 public function edit($id)
    {
        $makan = Gambar::find($id);
        return view('edit_upload',['makan'=>$makan]);
    }
    public function prosesedit($id, Request $request)
    {
        $makan = Gambar::find($id);
        $makan->nama_makanan = $request->input('makanan');

        if($request->hasfile('image'))
        {
            $file = $request->file('file');
            $nama_file = time()."_".$file->getClientOriginalName();
            $tujuan_upload = 'image_file';
            $file->move($tujuan_upload,$nama_file);
        }
        $makan->save();
        return redirect(route('makan'));
    }

最佳答案

请尝试这个


public function prosesedit($id, Request $request)
    {
        $makan = Gambar::find($id);



         $nama_file=$makan->file;




        if($request->hasfile('image'))
        {
            $file = $request->file('file');
            $nama_file = time()."_".$file->getClientOriginalName();


            $tujuan_upload = 'image_file';
            $file->move($tujuan_upload,$nama_file);
        }
        $makan->update([
         'file'=>$nama_file
]);
        return redirect(route('makan'));
    }


10-07 22:35