Problem

You want to see if a file exists.

You know you can use the PHP file_exists() method, but want to do it the Laravel way.

Solution

Use the File::exists() method.

if (File::exists($myfile))

{


    echo “Yup. It exists.”;

}

Discussion

This method actually calls file_exists().

But it does allow better testing because using the facade allows you to easily mock the method when needed.

About the author

Determining If a File Exists Laravel