0

I want to edit the picture, but it doesn't work. What is the syntax for editing a picture?

I tried the following in the controller:

 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'));
    }

1 Answer 1

0

Please Try this


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'));
    }


4
  • <div class="form-group"> <b>File Gambar</b> <br/> <input type="file" name="file" value="{{ $makan->image_file }}"> </div> <div class="form-group"> <b>Nama Makanan</b> <br/> <input type="text" name="makan"> </div> Commented Sep 25, 2019 at 1:58
  • where is your route to post this form Commented Sep 25, 2019 at 4:59
  • this is the route Route::get('/makanan/edit/{id_makanan}', 'MakananController@edit'); Route::post('/makanan/prosesedit/{id_makanan}', 'MakananController@prosesedit')->name('prosesedit'); Commented Sep 25, 2019 at 5:02
  • i said the full form of this blade Commented Sep 25, 2019 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.