Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: How to include file from Vendor folder in Laravel

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

like image 320
rnldpbln Avatar asked Feb 10 '14 08:02

rnldpbln


People also ask

Where is vendor file in Laravel?

The vendor is a subfolder in the Laravel root directory. It includes the Composer dependencies in the file autoload. php.

What is use of vendor folder in Laravel?

Laravel's Vendor directory The vendor directory contains the composer dependencies, for example, to install Laravel setup, the composer is required. The vendor folder contains all the composer dependencies.


2 Answers

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 :)

like image 110
Miroslav Trninic Avatar answered Sep 21 '22 14:09

Miroslav Trninic


Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so

echo base_path() . '/vendor';

Should be the route to your vendor folder.

You can se all the documentation in Helper Functions Laravel

Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).

like image 21
rebduvid Avatar answered Sep 21 '22 14:09

rebduvid