How can I add external class in Laravel 5 How can I add external class in Laravel 5 laravel laravel

How can I add external class in Laravel 5


First you should make sure that this class is in the right namespace. The correct namespace here would be:

namespace App\Libraries;class TestClass {

Then you can just use it like any other class:

$test = new TestClass();echo $test->getInfo();

Don't forget the import at the top of the class you want to use it in:

use App\Libraries\TestClass;

In case you don't have control over the namespace or don't want to change it, add an entry to classmap in your composer.json:

"autoload": {    "classmap": [        "app/Libraries"    ]}

Then run composer dump-autoload. After that you'll be able to use it the same way as above except with a different (or no) namespace.