9

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

Sam
  • 1,546
  • 4
  • 14
  • 22
  • Why and where are you trying to include `autoload.php`? Why can't you use `composer.json` to add your dependencies? – John Bupit Sep 15 '15 at 00:13
  • 1
    I used composer require to grab the package I needed, which it has but I need to include the autoload too right? – Sam Sep 15 '15 at 00:19
  • Try `php artisan dump-autoload` and `composer dump-autoload`. – John Bupit Sep 15 '15 at 00:22
  • Try `require_once 'C:\Users\Dell\vendor\autoload.php';` (specify username in my case its 'Dell') and then run `$composer update` and `$composer dump-autoload` – Santosh Dangare Apr 25 '21 at 06:29

1 Answers1

21

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.

Drown
  • 5,852
  • 1
  • 30
  • 49
  • Aha I see now thanks! I used the composer require and have the package, but how can I tell my app to include a class thats inside the package. – Sam Sep 15 '15 at 00:38
  • You should be able to use it directly, if you can't then make sure that you're using the proper namespace. Look into your library files to see what namespace it's using, but you should be able to find it on their documentation if they have any. – Drown Sep 15 '15 at 00:46
  • I have the same problem: require(F:\Xamp\htdocs\getme-backend-new\public/../bootstrap/autoload.php): failed to open stream. This is my error. Can you please tell me how to solve that? – Mahdi Jul 21 '20 at 03:34