问题描述:

I want to include an external PHP file into my service provider, that file is in a different folder.

Like my file is in folder1 and this folder is at same level as laravel is.

 C:\xampp\htdocs\registration\php\file.php //this is file

C:\xampp\htdocs\_problem_sharing\app\AppServiceProvider

This is how I am trying right now

include_once "/../../../registration/php/user_info.php";

网友答案:

Is really simple to do this. Because everything in Laravel 5 is autoloaded using PSR-4, within the app/ directory. So, for example, if this file you want to include have a class.

You need to create the directory, e. g.: app/CustomStuff/CustomDirectory/ Into this directory, create the file: app/CustomStuff/CustomDirectory/SomeClass.php

Into the SomeClass.php file, you just need:

<?php 
namespace App\CustomStuff\CustomDirectory;

class Someclass {}

Now, you can access this class using the namespace within your classes:

use App\CustomStuff\CustomDirectory\SomeClass;
相关阅读:
Top