I don't think it will work giving it a URL.
Have you tried this instead:
Storage::deleteDirectory('slides');
?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Will this works?
Storage::disk('public')->delete(http://localhost/aws_admin_test/storage/app/slides);
PageController.php
$slides = HomeSlidesModel::find($id);
$file = $request->file('slides');
if($file)
{
Storage::disk('public')->delete($slides->image);
$path = env('STORAGE_URL').$request->file('slides')->store('slides');
I would like to delete the old file before replacing it with a new one. When I run the program, I successfully upload a new slide but failed to delete the old file.
I don't think it will work giving it a URL.
Have you tried this instead:
Storage::deleteDirectory('slides');
?
I only want to delete one file not the whole directory.
If I don't use the url in the image column, I fail to show the image. So I have the url save in the column.
So I have to use the file path to delete it?
@davy_yg you should never store a FULL URL within the database but just the absolute path to the file. So you should have stored slides/your_file.jpg for example. And then delete it as such:
Storage::disk('public')->delete('slides/your_file.jpg');
Then I am having a problem with showing the image in the view:
home_slides.blade.php
<td><img src="<? env('STORAGE_URL') ?>.{{ $item->image }}"></td>
.env
STORAGE_URL=http://localhost/aws_admin_test/storage/app/
Help me correct the home_slides.blade.php
@davy_yg you will not have a problem if you take time to read the documentation.
So make a symlink to the storage directory in your public directory by running the artisan command:
php artisan storage:link
and then use it like this:
<img src="{{ asset($item->image) }}" />
// or
<img src="{{ asset('storage/' . $item->image) }}" />
okay I have created the storage:link
Yet, whenever I uploaded an image, it is not in public/storage/slides
it only exist in storage/app/slides/ which is in the root directory.
So I thought
<img src="{{ asset('storage/' . $item->image) }}" />
only addressing to the public directory
Is asset addressing to the public directory only?
@davy_yg yes, and that's the folder where your images should exist in order to be publicly available, but not in the storage directory, as that folder has different permissions and should not be available to the public.
The thing is my public/storage/slides remains empty eventhough I already move my images to storage/app/slides. Do I have to copy my images to the public/storage/slides with codes also?
No, thats what the php artisan storage:link command is for. It creates a symlink to your storage folder to connect your public/storage folder to your storage/app folder.
@davy_yg no, you don't have to manually copy the images, that's what the symlink does.
Do you use Vagrant? If you do, you need to ssh and run the php artisan storage:link within the box. Not from your local project.
Take a look at the answers here it will help you as those are exactly what your problem is atm.
https://laracasts.com/discuss/channels/laravel/storage-link-not-loading-image-after-symlink
I am using Win 10 and already run php artisan storage:link. Yet, whenever I upload a new image in storage/app/slides, it does not copy to public/storage/slides.
It shouldn't copy. A symlink is basically a mirror of the directory. They are the same files.
In Windows it's a little different. How are you hosting your Laravel project? Locally? Vagrant? Docker?
@davy_yg the path seems incorrect as you say it. If you use Storage::disk('public') then your path to the storage folder should be :
storage/app/public/slides
Which after the symlink will create public/storage/slides
So please read some answers on the post that I provided above and follow them.
I am using xampp on Windows and it is local. @nakov your link is not for Windows.
@davy_yg I should not teach you how to google, right? I gave you directions on where to look, so you should google an answer for that:
https://stackoverflow.com/questions/52637260/cant-display-image-in-laravel-running-on-local-xampp
I successfully delete the old file. Now, I have three options:
home_slides.blade.php
<td><img src="{{ env('STORAGE_URL').$item->image }}"></td>
<td><img src="{{ url('storage/'.$item->image) }}"></td>
<td><img src="{{ env('APP_URL').Storage::url('app/'.$item->image) }}"></td>
The middle one is reading the public/storage/slides, yet it return nothing since the image is not copied there.
The first one and the third one work! It reads from the storage/app/slides which is in laravel root folder. Is it okay to read from there? I also wonder what is the point of having the public/storage folders?
Never use env() outside of your config directory! Use config() instead.
Once you cache your application it will break :)
Regarding public/storage.. I use it like this myself.. In my filesystems.php (config file) i have the following
'assets' => [
'driver' => 'local',
'root' => storage_path('app/public/static-assets'),
'url' => env('APP_URL').'/storage/static-assets',
'visibility' => 'public',
],
This is shared on my company network and colleagues can dump assets to use in mails etc. in there.
Then in our system I can easily load them from storage and and get a url for each.
$assets = Storage::disk('assets');
$url = $assets->url($file_name); //Url to the asset
$path = $assets->path($file_name); //The local path to the asset (if I need to work with the actual file)
No it's not okay. Only content inside of the public directory should be accessible from the "outside" (so CSS, JS, Image files etc). That's the reason why you need the public/storage folder because the public directory shouldn't be writeable by the server, only the storage folder should be writeable.
So you combine the two.
See I cannot understand why there is no image in my public/storage/slides directory? I already run the php artisan storage:link and I am using Windows localhost.
Should it mirror the storage/slides folder contents which is in the laravel root directory?
Storage link links to storage/app/public, not to storage/slides. So you need to put your uploaded images into storage/app/public/slides so the symlink can work.
What is the exact folder that these images are in inside /storage?
Okay, I successfully upload my image to storage/app/public/slides/uploaded-image.jpeg yet nothing remains in my public/storage/slides/ folder.
Try deleting the /public/storage folder and run php artisan storage:link again. Does the folder show up again automatically?
Are you sure that the "storage" in your public directory is a symlink and not a normal directory?
public/storage it has a folder with a chain image. I did try uploading the file once again and still public/storage remains empty.
And if you delete the folder and symlink again, you get the /public/storage/slides/ folder again?
I get public/storage folder only if I delete the folder and symlink again (php artisan storage:link).
Another question:
If I run:
//storage/app
Storage::delete($slides->image);
It is reading from:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
correct?
I expect that you are using git bash to run the command? Can you try starting it as administrator (right click the icon)
Please or to participate in this conversation.