On edit.blade.page
there is a button for file deleting which leads to the update
method in a controller. The update
method calls private deleteImage
method from which I want to redirect a user back to edit.blade.page
, but it redirects me somewhere else.
I have tried all approach from the documentation
Controller
public function update(Request $request, $id){
($request['method']==true) ? $this->imageDelete($request, $id) : null;
}
private function imageDelete (Request $request, $id){
if($request['method']=='destroy'){
$file = public_path().'/storage'.$request['old_image'];
$validatedData = $request->validate(['images'=> 'string',]);
$old_images = explode(',', $request['images']);
$paths = array();
foreach ($old_images as $old){
($old != $request['old_image']) ? $paths[] = $old : null ;
}
(File::exists($file)) ? File::delete($file) : null;
Announcement::where('slug', $id)->update(array_merge($validatedData,array('images'=>implode(",",$paths),)));
return redirect()->route('announcements.edit',[$id])->with('status',1);
}
return redirect()->route('announcements.edit',[$id])->with('status', 0);
}
Route
Route::resource('announcements', 'AnnouncementController', ['names' => [
'index' => 'announcements',
'store' => 'announcements.store',
'show' => 'announcements.show',
'destroy'=>'announcements.destroy',
'update' => 'announcements.update',
]])