How can I update image in edit view in laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company

Updating Profile Picture in Laravel Edit View

In Laravel, updating profile pictures while editing can be achieved using the correct approach. You need to incorporate some logic in your code and Blade files that handles both uploading new images and keeping existing ones when not necessary. Here is a comprehensive breakdown of how it can work.

Blade File

The view for editing an employee profile should include inputs for the personal details as well as the image input with the appropriate code to display the current profile picture. Your Blade file might look like this: ```HTML @extends('layouts.app') @section('content')

Edit Employee Profile

@if(Session::get('Success'))
{{ Session::get('Success') }}
@endif @foreach ($empProfilePic as $empProfilePicture) @if($employee->id == $empProfilePicture->id) @endif @endforeach
@csrf @method('PUT')
@include('includes.personal_details_inputs', ['emp' => $employee])
@foreach ($empProfilePic as $empProfilePicture) @if($employee->id == $empProfilePicture->id) @endif @endforeach
@endsection ```

Controller File

In your controller file, you can handle the updating process. For each employee update, verify if a new image is uploaded or not. If there's no image file attached, use the current profile picture, otherwise store and set the new image path. Here's an example: ```PHP public function updateEmployee(Request $request, $id) { // Rest of your code // Store Image In Folder $file = $request->file('file'); if ($file != null) { $name = $file->getClientOriginalName(); $file->move('uploads/images', $name); // Update Image in Database $employee->file = $name; } else { foreach ($empProfilePic as $empProfilePicture) { if ($employee->id == $empProfilePicture->id) { $name = $empProfilePicture->file; break; } } $employee->file = $name; } // Continue the rest of your code to update and save the employee details. } ``` By combining these two files, you can successfully allow users to edit an employee's personal information while maintaining their profile picture either by uploading a new one or keeping the existing one. For more comprehensive examples, please refer to Laravel documentation for working with file uploads and images.