/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $background = Background::find($id); $filename = $background['name']; $default_backgrounds = ['home-bg1.jpg', 'home-bg2.jpg', 'home-bg3.jpg', 'home-bg4.jpg', 'home-bg5.jpg', 'home-bg6.jpg']; if (!in_array($filename, $default_backgrounds)) { $file_path = public_path("images/backgrounds/{$filename}"); if (File::exists($file_path)) { File::delete($file_path); } } Background::destroy($id); return redirect('admin/backgrounds'); }