What is autoload.php in 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

asked Sep 14, 2015 at 23:58

4

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.

answered Sep 15, 2015 at 0:21

DrownDrown

5,7141 gold badge30 silver badges47 bronze badges

3

Jan 24, 2021 15:46

In this post we will code a custom autoloading solution in Core PHP from scratch and will also take a look at utilizing composer for autoloading in Core PHP.

If you have used a framework like laravel, you may wonder how it autoload classes without including a source php file of that class.

In core php, You have to include the source file of the class in order to use it somewhere in another file.

for example:

Chủ Đề