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

46

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

Sign up to request clarification or add additional context in comments.

4 Comments

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?
i will edit answer,, actualy its easy check edit (i just tested the answer and it works 100% )
Loving the Game of Thrones reference.
In Laravel 11 , for directory renaming Storage::disk('public')->move('oldFolder/', 'newFolder/'); is worked for me.
2

You can rename directories using

Storage::rename('oldFolder/', 'newFolder/'); 

1 Comment

Was looking for an answer to this question. Both using rename and move for renaming a folder doesn't work. Any ideas?
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!

1 Comment

You need to consider that in Laravel the directory or file may not be local. In those cases rename would not work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.