I am using Laravel 5.5, and I have problems to update images and videos. The thing here is that I have an index of my videos, these videos are being uploades to a folder (\storage\app\public\videos) this path has been linked whith the command:

php artisan storage:link

I have no problem storing any file, I use the following code on my controller:

$videoName = "".$request->user."_".$request->propiedad."_".$videoNumber.".mp4";

$request->video->storeAs('public/videos', $videoName);

As I said everything works fine, but if I try to update this file, I save it with the same name using the same code:

$request->video->storeAs('public/videos', $videoName);

And it saves when i check the folder, but the view displays the old video instead of the new one, i am not sure what is going on I have tried to clear cache but is not working.

upvote
  flag
Have you tried clearing your browser cache? You should even check by trying php artisan cache:clear also. – Imran
upvote
  flag
Thanks, but I have done that many times, It doesn’t seem to work, it takes too much time until it works – Alex VTz

1 Answers 11

Check if the file exist. if yes, then delete it and upload the new one.

$videoName = "".$request->user."_".$request->propiedad."_".$videoNumber.".mp4";

if(Storage::exists('public/videos' . $videoName)) {
    Storage::delete('public/videos' . $videoName);
}

// Save the video
$request->video->storeAs('public/videos', $videoName);

Deleting a file

Checking if the file exists

upvote
  flag
Don't just link webpages, add some content to your answer - some users don't like to open websites continuously - paste the code from laravel.com here too. – Optiroot
upvote
  flag
Thanks for your help, Christian, but It doesn’t work just by checking the existance of the file – Alex VTz

Not the answer you're looking for? Browse other questions tagged or ask your own question.