Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adamnet's avatar

I accidentally deleted a Controller. How to recover?

Hello. I accidentally deleted a Controller. The last backup was two days ago. These two days I had made too many improvements and changes in this Controller. Is there any case to recover?? Is there some Recycle Bin for Larave?

1 like
7 replies
JussiMannisto's avatar

If you use version control, such as Git, recovery is easy. Every developer should always use version control, even if they're working alone.

Another easy way is through an IDE. PhpStorm has a local history that shows file deletions, which you can revert. VS Code is a bit worse in this regard, but it's still possible.

Otherwise, you might be able to do it with some recovery tool. Recovering deleted files is less likely on SSDs than HDDs. Your best bet is to google "undelete tool" and try something to recover it. Recovery becomes less and less likely the longer you keep using the device.

1 like
Glukinho's avatar

No, recovering your local deleted files is out of Laravel responsibility. You should search in your local system for such things.

If you use version control system (most likely Git) and committed your controller then search there. But I'm afraid that's not the case otherwise you wouldn't ask.

As last chance you can use some data recovery software and most likely you'll find your file as deleted files are not actually erased from disk. I successfully used R-Studio: https://www.r-studio.com/

But I think rewriting the class is the best option for you. It is not so hard to do, you'll polish the logic at the same time. Rewriting actually helps.

1 like
ghabriel25's avatar

If you're using vscode, there is timeline local history that can be used to retrieve lost file. This only if you're not clearing any temporary file in your OS

Image

1 like
vincent15000's avatar

It's independent from Laravel, the way to retrieve your controller only depends on your file system and the use of git.

If you are using git (it's the base for all developpers), you can retrieve the file from an old commit.

If you are not using git, the only way is to scan your file system with an appropriate tool to retrieve deleded files.

martinbean's avatar

@adamnet This is what version control is for. And I’m sure you had been advised to use version control some time ago…?

JussiMannisto's avatar

Oh, you're right: thread.

@adamnet You keep making the same mistake and asking the same question. Either accept that you'll occasionally lose work, or start using version control. If you want to be a serious developer, learn version control.

ghabriel25's avatar

I learn the hard way so please use version control before your entire project accidentally deleted

Please or to participate in this conversation.