You want to check that the file exists, not the url.
@if(Storage::disk('images')->exists($filename))
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
With this code, my index.blade.php will load and display images:
@foreach( $portfolios as $portfolio)
<img src="{{Storage::disk('images')->url( $portfolio->picture )}}" height=200 width=300 }}" >
@endforeach
If the file does not exist, a default image should display:
{{Storage::disk('images')->url( 'default.jpg' )
I have not been able to devise a test for the existence of the $portfolio->picture file.
The following always returns TRUE, even if the file does not exist:
@if( file_exists( "{{Storage::disk('images')->url( $portfolio->picture )}}" ) )
Bingo!
@endif
I'm so close I can taste it, but it's eluding me.
Any suggestions? I would be most grateful.
Please or to participate in this conversation.