How to delete files from Laravel app directory (not the public directory but the one in the root)?
I tried :
\Storage::Delete('App\file.php');
\Storage::Delete('\App\file.php');
\File::Delete('App\file.php');
\File::Delete('\App\file.php');
unlink ('\App\file.php');
Nothing works.
UPDATE:
The file is in something like \App\folder\folder\file.db
When not specifying an absolute path then what is used is the current working directory (the value that getcwd()
would return). Usually, that's the /public
directory and not the actual project root.
You need to specific an absolute path using the Laravel helpers:
\File::delete(app_path('file.php'));
Note: You can't use the \Storage
helpers because they are limited to only work within the app storage folder.