Exit fullscreen mode #init-file-input init file input Exit fullscreen mode https://res.cloudinary.com/practicaldev/image/fetch/s--RvXSzFD9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gg6pezsl8dmi5tmifkv.png #server server public function store(){ $images = []; $files = $request->images; foreach($files as $file){ $textRandom=Str::random(20).time(); $extenstion= $file->getClientOriginalExtension(); $fileName=$textRandom.".".$extenstion; $file->move(public_path('uploads/'), $fileName); $images[]=["name"=>$fileName ]; } Exit fullscreen mode #edit-images edit images #server server public function get_images(){ $images = Image::get(); return view('edit',compact('images')); } public function destroyImg($imgId){ $img=Image::whereId($imgId)->first(); // check image in database if(!$img){ return response() ->json(['error'=>'Sorry, the image is not in the database']); } // check image in files if(!File::exists('uploads/'.$img->name)){ return response() ->json(['error'=>'Sorry, the image is not in the file folder']); } unlink('uploads/'.$img->name); $img->delete(); return true; }