Laravel: How to include file from Vendor folder in Laravel

rnldpbln picture rnldpbln · Feb 10, 2014 · Viewed 34k times · Source

I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.

include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')

It is not working, because it defaults to the App folder.

How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?

The error is {

include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php): failed to open stream: No such file or directory

Answer

Miroslav Trninic picture Miroslav Trninic · Feb 10, 2014

From where do you want to include that file ?

Place a reference to your file in composer.json autoload object:

"autoload": {
    "files":["your_file_path"]
}

Run composer dumpautoload, and you'll have your file :)