1
votes

When I modify the images, the editing process succeeds, but no changes are made to the pictures and the new image does not appear after the edit except when I delete the cache

 $brands = Brands::findOrfail($id);


    $image = $request->file('image');

    if ($image && $image->isValid()) {
        $path = $image->storeAs('brands', basename($brands->image),'public');
        $brands->image = $path;
    }


    $brands->name = $request->input('name');
    $brands->description =$description;

     if ($brands->save()) {
        return redirect(route('admin.brands'))->with([
            'message' => sprintf(' The Brand: "%s" edit success !', $brands->name),
            'alert-type' => 'success'
        ]);
    } else {
        return redirect()->back()->with([
            'message' => sprintf(' The Brand : "%s" can not edit success !', $brands->name),
            'alert-type' => 'error'
        ])->withInput();
    }
1
please give codealbus_severus

1 Answers

1
votes

It may be caused by images having same filenames, images are often saved to cache by default so if the images have same filenames, the browser will show the old one from the cache.

It's better to change the filename of image every save or edit/update, and use hash so that there will be no duplicate image filenames.

Another reason is that maybe you are not fetching data back after saving so that the image is not updated. Always remember to have a reply from your request for confirmation. It's either a reply that will trigger a function to refresh the data or the data itself.