Skip to content

Commit

Permalink
Update User profile updatation.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Jun 25, 2024
1 parent cbe9f16 commit 15a614c
Showing 1 changed file with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Webkul\Admin\Http\Controllers\Controller;

class AccountController extends Controller
Expand Down Expand Up @@ -61,13 +62,7 @@ public function update()
$data['password'] = bcrypt($data['password']);
}

if (request()->hasFile('image')) {
$data['image'] = request()->file('image')->store('users/' . $user->id);
}

if (isset($data['remove_image']) && $data['remove_image'] !== '') {
$data['image'] = null;
}
$this->handleProfileImageUpload($data, $user);

$user->update($data);

Expand All @@ -79,4 +74,38 @@ public function update()

return redirect()->route('admin.dashboard.index');
}

/**
* Handle profile image upload.
*
* @param array $data
* @param Object $user
* @return void
*/
public function handleProfileImageUpload(&$data, $user)
{
$oldImage = $user->image;

if (! isset($data['image'])) {
$data['image'] = $user->image;
}

if (request()->hasFile('image')) {
$data['image'] = request()->file('image')->store('users/' . $user->id);
}

if (
isset($data['remove_image'])
&& $data['remove_image'] !== ''
) {
$data['image'] = null;
}

if (
$oldImage
&& ($data['image'] !== $oldImage)
) {
Storage::delete($oldImage);
}
}
}

0 comments on commit 15a614c

Please sign in to comment.