Search code examples
phplaravellaravel-4

Laravel 4.2: Include a PHP file (library) into controller


I'm doing a project using Laravel 4.2 where I need to include a PHP file (a library to transform a PDF into Text) into the controller, and then return a variable with the text, any idea how?

This is my controller:

public function transform() {
    include ('includes/vendor/autoload.php');
}

And my /app/start/global.php file:

ClassLoader::addDirectories(array(
    app_path().'/commands',
    app_path().'/controllers',
    app_path().'/models',
    app_path().'/database/seeds',
    app_path().'/includes',

));

And this is the error:

include(includes/vendor/autoload.php): failed to open stream: No such file or directory

Solution

  • I think you're right bro, but, i find another way, maybe not the right way, but it works.

    Is like this, I created a new folder called Includes and put my files in there, then in the /app/start/global.php i added this line:

    require app_path().'/includes/vendor/autoload.php';
    

    And now is working :D