Laravel 5如何包含autoload.php [英] Laravel 5 how to include autoload.php

查看:60
本文介绍了Laravel 5如何包含autoload.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在其中包含指向autoload.php的路径

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

我将路径设置为require_once '../vendor/autoload.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')

laravel是否提供访问供应商文件中文件的简码

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

推荐答案

您不需要在Laravel应用程序中要求autoload.php,它已经是必需的.您可以在composer.json文件中添加更多程序包,或者在命令行中执行composer require,它应该可以工作.

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.

如果您不相信我,这是bootstrap/autoload.php中所必需的. ;)

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';

如果由于某种原因而没有尝试,请尝试composer dump-autoload,它解决了Laravel中的许多要求"问题,尤其是在使用播种机之类的东西时.

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.

这篇关于Laravel 5如何包含autoload.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆