如果Laravel的Blade模板检查文件是否存在 [英] Check for file existence if Laravel's Blade template
本文介绍了如果Laravel的Blade模板检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的问题-如何检查Laravel的Blade模板中是否存在文件? 我尝试过
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
但是它不起作用(covers
目录位于/public
中).我还需要为该函数提供一个变量($game->id
).不幸的是
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
不起作用.
推荐答案
这对我有用,favicon.ico在公共内部:
This is working for me, favicon.ico is inside public:
@if(file_exists('favicon.ico'))
File exists
@else
Could not find file
@endif
所以我认为您只需要使用@if(file_exists('covers/1.jpg'))
So I think you just have to use @if(file_exists('covers/1.jpg'))
这篇关于如果Laravel的Blade模板检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文