Search code examples
phplaravel-5file-exists

How to check if a file exists in Laravel 5.2


I have tried the following method to check if file exist:

@if(file_exists(public_path('/user_img/'.Auth::user()->id.'.jpg')))

It returns false even when the file exists!

What is wrong with it?


Solution

  • I have corrected by adding curly braces to the User id and it works fine:

    @if(file_exists(public_path().'user_img/{{ Auth::User()->id }}.jpg'))