12

I'm using Laravel 5.0 Facades Storage

use Illuminate\Support\Facades\Storage;

and I can use it like

Storage::..

In the Laravel 5.0 Docs,there's nothing like rename a file or folder from the storage.

Any help, ideas, clues, suggestions, recommendations on how to rename a file or folder using the Storage?

3 Answers 3

45

Laravel Docs

The move method may be used to rename or move an existing file to a new location:

Storage::move('hodor/file1.jpg', 'holdthedoor/file2.jpg');

this way, you can rename without moving

Storage::move('hodor/oldfile-name.jpg', 'hodor/newfile-name.jpg'); // keep the same folder to just rename 

Source

2
  • i see, in php it could be like 'rename(oldname,newname,context)' so I'm looking for Laravel's way, anyway, thanks for the answer, how can I rename the file without moving it? Jun 1, 2016 at 1:18
  • i will edit answer,, actualy its easy check edit (i just tested the answer and it works 100% ) Jun 1, 2016 at 1:19
2

You can rename directories using

Storage::rename('oldFolder/', 'newFolder/');
1
  • Was looking for an answer to this question. Both using rename and move for renaming a folder doesn't work. Any ideas?
    – eskimo
    Dec 16, 2020 at 18:44
0

Well, I had almost the same issue but i solved it like this: rename($path, $newPath) using the built-in php function rename(),and guess what, everything worked like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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