Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix old image not removed on update #5196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Http/Controllers/VoyagerBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,19 @@ public function update(Request $request, $id)

// Validate fields with ajax
$val = $this->validateBread($request->all(), $dataType->editRows, $dataType->name, $id)->validate();

// Get fields with images to remove before updating and make a copy of $data
$to_remove = $dataType->editRows->where('type', 'image')
->filter(function ($item, $key) use ($request) {
return $request->hasFile($item->field);
});
$original_data = clone($data);

$this->insertUpdateData($request, $slug, $dataType->editRows, $data);

// Delete Images
$this->deleteBreadImages($original_data, $to_remove);

event(new BreadDataUpdated($dataType, $data));

if (auth()->user()->can('browse', app($dataType->model_name))) {
Expand Down