2 months ago

How to update file upload laravel ?

Posted 2 months ago by adhik13th

I have a edit form , and this edit form is can changes imageupload . i can show this image. but on store function update is not work properly . only image cant updated .

its my store function

 public function update_non_pns(Request $request,$id)
    $users  = User::find($id);

    $users->nama                 = $request->input('nama');
    $users->email                = $request->input('email');
    $users->alamat               = $request->input('alamat');
    $users->NIK                  = $request->input('NIK');
    $users->jenis_kelamin        = $request->input('jenis_kelamin');
    $users->tempat_lahir         = $request->input('tempat_lahir');
    $users->tanggal_lahir        = $request->input('tanggal_lahir');
    $users->pendidikan           = $request->input('pendidikan');
    $users->nomor                = $request->input('nomor');
    $users->agama_id             = $request->input('agama_id') ;
    $users->status_pegawai_id    = $request->input('status_pegawai_id');
    $users->unit_kerja_id        = $request->input('unit_kerja_id') ;


    $file = $request->file('foto');
        $extension = $request->foto->getClientOriginalExtension();  //Get Image Extension
        $fileName = uniqid().'.'.$extension;  //Concatenate both to get FileName (eg: file.jpg)
        $file->move(public_path().'/files/', $fileName);  
        $data = $fileName; 
        $users->foto = $data;

    //  $users->save();
    //  return redirect()->back()->with('success', 'Your info are updated');

i have some update function to edit File not Image , this file can update successfully but i use this function to image its cant be updated .

i try to dd($request->foto): its success and show a true image on my input , so

whats wrong on my store function ?

Please sign in or create an account to participate in this conversation.