In this tutorial i’m going to solve how to use after upload image should be unlink in our public path after upload new file its automatically should be unlink using this tutorial i have mentioned in very easy way.
- 1st step
Got to your controller function and put below code as well.
public function AdminProfileStore(Request $request){
$id = Auth::user()->id;
$data = User::find($id);
$data->name = $request->name;
$data->email = $request->email;
$data->phone = $request->phone;
$data->address = $request->address;
if($request->file('photo')){
$file = $request->file('photo');
unlink(public_path('upload/admin_images/'.$data->photo));
Log::info("file me kya aa rha hai".$file);
$filename = date('YmdHi').$file->getClientOriginalName();
$file->move(public_path('upload/admin_images'),$filename);
$data->photo = $filename;
}
$data->save();
return redirect()->back();
}
Now upload image and check its unlink is working properly.
Now here showing only 1 image it working unlink function.
Now image name also store.