Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom class in laravel 5.4.10

I am new in laravel. I am writing following code in the controller method.

include_once(app_path() .'/Classes/Pgp_2fa.php');
$pgp = new Pgp_2fa();

Following errors are shown.

FatalThrowableError in AuthController.php line 146: Class 'App\Http\Controllers\Pgp_2fa' not found

like image 843
Woodpecker Avatar asked Jan 27 '23 12:01

Woodpecker


1 Answers

You have to use the correct namespace for your class.

If you are not using any namespace, you should add a \ in front of the class to let php know that the class exists in the root namespace. Otherwise php will look in the current namespace which is App\Http\Controllers when you are in a controller.

$pgp = new \Pgp_2fa();

This is not just Laravel behavior but php in general.

like image 187
Jerodev Avatar answered Jan 30 '23 05:01

Jerodev