Requiring a File Once

Problem

You want to require a file one time only.

You know you can use PHP's require_once statement, but want to do it the Laravel way.

Solution

Use the File::require_once() method.

File::requireOnce($some_php_file);

Discussion

This is a wrapper over require_once.

And just like require_once a fatal error will occur if the file is missing.

comments powered by Disqus