如果Laravel的Blade模板检查文件是否存在

Tom*_*ski 3 laravel laravel-4

我有一个简单的问题 - 如何检查Laravel的Blade模板中是否存在文件?我试过了

@if(file_exists('/covers/1.jpg')) ok @endif
Run Code Online (Sandbox Code Playgroud)

但它不起作用(covers目录在/public).我还需要为$game->id函数提供一个variable().Unformtunately,

@if(file_exists('/covers/'.$game->id.'.jpg')) ok @endif
Run Code Online (Sandbox Code Playgroud)

不起作用.

Ant*_*iro 19

这对我有用,favicon.ico在公众场合:

@if(file_exists('favicon.ico')) 
  File exists
@else
  Could not find file
@endif
Run Code Online (Sandbox Code Playgroud)

所以我认为你只需要使用 @if(file_exists('covers/1.jpg'))


Ahm*_*mad 8

在Laravel 4中你可以使用:

 @if (file_exists(public_path('covers/1.jpg')))
Run Code Online (Sandbox Code Playgroud)

使用public_path获得该文件的物理路径.