我正在尝试包含一个指向 autoload.php 的路径
vendor/autoload.php
试图访问它的文件在
public/this-file.php
我将路径设置为 require_once '../vendor/autoload.php';
但它只是抛出错误 -
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')
laravel 是否提供短代码来访问供应商文件中的文件
最佳答案
你不需要在 Laravel 应用程序中要求 autoload.php
,它已经被要求了。您可以在 composer.json
文件中添加更多包,或者在命令行中执行 composer require
,它应该可以工作。
bootstrap/autoload.php
中需要它,如果你不相信我的话。 ;)
/*
|--------------------------------------------------------------------- -----
| 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';
如果由于某种原因不是,请尝试 composer dump-autoload
,它修复了 Laravel 中的许多“需要”的问题,尤其是在使用播种器和诸如此类的东西时。 p>
关于php - Laravel 5 如何包含 autoload.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32575659/