I have a simple problem - how can I check if file exists in Laravel's Blade template? I tried
@if(file_exists('/covers/1.jpg')) ok @endif
But it doesn't work (covers
directory is in /public
). I also need to provide a variable ($game->id
) to the function. Unformtunately,
@if(file_exists('/covers/'.$game->id.'.jpg')) ok @endif
doesn't work.
This is working for me, favicon.ico is inside public:
@if(file_exists('favicon.ico'))
File exists
@else
Could not find file
@endif
So I think you just have to use @if(file_exists('covers/1.jpg'))
In Laravel 4 you can use:
@if (file_exists(public_path('covers/1.jpg')))
Use public_path
to get the physical path to the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With