Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 how to include autoload.php

Tags:

php

laravel

I'm trying to include a path to autoload.php which is in

vendor/autoload.php

the file trying to access it is in

public/this-file.php

I set the path to require_once '../vendor/autoload.php'; but it just throws the error -

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

Fatal error: require_once(): Failed opening required '../vendor/autoload.php' (include_path='.:/opt/php55/lib/php')

Does laravel offer a shortcode to access files in the vendor file

like image 918
Sam Avatar asked Sep 14 '15 23:09

Sam


1 Answers

You don't need to require autoload.php in a Laravel application, it's already being required. You can just add more package in your composer.json file or do a composer require in the command line, and it should work.

It is required in bootstrap/autoload.php, if you don't believe me. ;)

/*
|---------------------------------------------------------------------  -----
| Register The Composer Auto Loader
|-------------------------------------------------------------------------    -
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

If it doesn't for some reason, try composer dump-autoload, which fixes a lot of "requiring" issues in Laravel, especially when working with seeders and that sort of thing.

like image 88
Drown Avatar answered Nov 09 '22 05:11

Drown