Karabah
Karabah

Reputation: 249

Using namespace and use in php/laravel?

I have two files in the same directory Graph:

IModel.php

DataModel.php

For these files in the top I set namespace as: namespace App\Library\Graph;

When I try to use IModel.php in DataModel.php I do:

namespace App\Library\Graph;

use IModel;

I get response: Interface 'IModel' not found

Upvotes: 0

Views: 20

Answers (1)

Joseph_J
Joseph_J

Reputation: 3669

You need to include the php file and then you will be able to call the class.

require('App\Library\Graph\IModel.php');

$myClass = new IModel();

You can also use an autoloader.. Then include the autoloader and all your classes that are mapped through the autoloader will be able to be called.

Here is a link to read about autoloading using composer.

https://phpenthusiast.com/blog/how-to-autoload-with-composer

Upvotes: 1

Related Questions