我想将一个外部 PHP 文件包含到我的服务提供商中,该文件位于不同的文件夹中。 就像我的文件在 folder1 中,这个文件夹与 laravel 处于同一级别。
C:\xampp\htdocs\registration\php\file.php //this is file
C:\xampp\htdocs\_problem_sharing\app\AppServiceProvider
我现在就是这样
include_once "/../../../registration/php/user_info.php";
最佳答案
要做到这一点真的很简单。因为 Laravel 5 中的所有内容都是使用 PSR-4 自动加载的,在 app/目录中。因此,例如,如果您要包含的这个文件有一个类。
您需要创建目录,例如。例如:app/CustomStuff/CustomDirectory/
在此目录中,创建文件:app/CustomStuff/CustomDirectory/SomeClass.php
进入SomeClass.php文件,你只需要:
<?php
namespace App\CustomStuff\CustomDirectory;
class Someclass {}
现在,您可以使用类中的命名空间访问此类:
use App\CustomStuff\CustomDirectory\SomeClass;
关于php - 在 laravel 中包含外部 php 文件(不在 laravel 目录中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34518646/