include a file in laravel controller code example
Example 1: include a file in laravel controller
require_once __DIR__ . '/../app/Utilities/FileName.php';
Example 2: include a file in laravel controller
If you have a custom file containing some classes/functions that need to be\
loaded for every request, you need to make sure its added to the autoloader.
In your composer.json add the following in your autoload section:
"autoload": {
"files": [
"path/to/your/File.php"
]
}
OR
First, make sure you have a namespace declaration at the top of your included
file - say namespace Your\Namespace. In order to avoid conflicts, you need
to explicitly tell PHP which class you mean when you reference it in the code. You mentioned your file contains a Response class that also exists in Laravel. In order to be able to use both, you need to alias one of them:
use Illuminate\Http\Response as LaravelResponse;
use Your\Namespace\Response;