lundi 17 février 2020

delete previous image after updating the new one in laravel

I updated and image is showed after that, but i need to delete the previous image(from folder) after updating with the new one. Need some help please! Thanks!!! I updated and image is showed after that, but i need to delete the previous image(from folder) after updating with the new one. Need some help please! Thanks!!! I updated and image is showed after that, but i need to delete the previous image(from folder) after updating with the new one. Need some help please! Thanks!!!

//update
    public function edit ($id)
    {
      $user = User::find($id);
      // $user = User::where('id', $id)->first();
      // $user = DB::table('users')->where('id', $id)->first();

      return view('edit', compact('user'));
    }

    public function postEdit (Request $request) {
      request()->validate([
          'email' => 'required',
          'fullname' => 'required',
          'birthday' => 'required',
          'address' => 'required|min:10',
      ]);

      $image = $request->image;
      // dd($image);
      $id = $request->id;
      $email = $request->email;
      $fullname = $request->fullname;
      $address = $request->address;
      $birthday = $request->birthday;
      $country = $request->country;



      $image = $request -> file('image');
      $destination = base_path().'/public/img';
      $file_name = rand(100,1).date('h-i-s');
      $image->move($destination, $file_name.".".$image->getClientOriginalExtension());
      $img = $file_name.".".$image->getClientOriginalExtension();



      User::where('id',$id)->update([
        'image'    => $img,
        'email'    => $email,
        'fullname' => $fullname,
        'birthday' => $birthday,
        'address'  => $address,
        'country'  => $country,
      ]);

      return Redirect::to("dashboard")->withSuccess('Great! You have Successfully edited');
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31ZqFCO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire