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, you get the image url of the relevant id value from the database. You can then delete the relevant data using the Storage :: delete () function. See details here: <https://laravel.com/docs/8.x/filesystem#deleting-files>