Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Galavant's avatar

Importing my own PHP file in Laravel

I have an php file(SOAP connection) with multiple classes in it that I would like to import into a controller

I've used

The file is located at app/Functions/nusoap.php

require_once(app_path() . '\Functions\nusoap.php');

$client = new nusoap_client('URL', true);
include_once(app_path() . '\Functions\nusoap.php');


  $client = new nusoap_client('URL', true);

Everytime I get the following error

Class 'App\Http\Controllers\nusoap_client' not found

The nusoap_client class is present in the PHP file I included and/or required.

What am I doing wrong?

0 likes
4 replies
Vilfago's avatar

don't include it, just use it

At the beginning of your controller

<?php 
namespace App\Http\Controllers;

use App\Functions\nusoap;
use App\Http\Controllers\Controller;

class FooController extends Controller
{
    [...]
}

1 like
tykus's avatar
tykus
Best Answer
Level 104

It is a file that has multiple classes @Vilfago so aliasing it will not work

The require approach should work, but since it is in the global namespace, you should preceed the class name with a \:

$client = new \nusoap_client('URL', true);
1 like
Galavant's avatar

The answer of @tykus worked for me.

Thank you for both of your answers

Please or to participate in this conversation.