Question: name of controller is "EmployeeController", How i can delete old image after updating. Please help me.
This is my update function in controller

```
public function update(Request $request, $id)
{
    $employee = Employee::find($id);

    $request->validate([
        'first_name' =>  'required',
        'last_name' =>  'required',
        'profile_image' =>  'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);

    $profile_image = $request->file('profile_image');

    $new_name = rand() . '.' . $profile_image->getClientOriginalExtension();
    $profile_image->move(public_path('profile_image'), $new_name);
    $employee->first_name = $request->first_name;
    $employee->last_name = $request->last_name;
    $employee->profile_image = $new_name;

    // $employee->delete('/profile_image/'.$employee->profile_image);

    if($request->hasFile('image')){
        //
    }

    $employee->save();

    return redirect('employees')->with('success', 'Data Added successfully.');
}

```

This is my Edit function in controller

```
public function edit($id)
{
    $employee = Employee::find($id);

    return view('employees.edit', compact('employee'));
}

```

Answer: 
```
 if ($request->hasFile('image')) {
                $imagePath = public_path('employeeImg/'.$user->image);
                if(File::exists($imagePath)){
                    unlink($imagePath);
                }

            }

```

you can check if image exist then unlink from path and then save new
First Thing You Should know how you are saving the images inside the database, get the path of them and use this simple delete.

Ex :

```
File::delete(public_path('storage/'.$user->image));

```

also u must check if the image column is not empty, if it is not empty it must delete it with the code above. else it'll just upload it without deleting anything.