0

I'm having an issue within a Laravel controller, I'm not sure where to begin troubleshooting. Basically 2 separate methods are calling the same external class; the process method works, however when calling process3d I run into the error class 'App\Services\PaymentGateway\Gateway\RequestGatewayEntryPointList' not found.

DebugController.php

namespace App\Http\Controllers;
use App\Services\PaymentGateway\Gateway\RequestGatewayEntryPointList;
...
public function process(Request $request) {
   ...
   $rgeplRequestGatewayEntryPointList = new RequestGatewayEntryPointList;
   ...
}

public function process3d(Request $request) {
   ...
   $rgeplRequestGatewayEntryPointList = new RequestGatewayEntryPointList;
   ...
}

PaymentSystem.php

namespace App\Services\PaymentGateway\Gateway;
...
class RequestGatewayEntryPointList {
   ...
}

I've omitted irrelevant code to keep the question brief, but I'm of course happy to provide more details if it will help.

What's going on?

3
  • And you are using both functions inside the same controller, DebugController.php? Commented Jul 29, 2020 at 16:58
  • 1
    Yes, just to clarify- I was. However in the process method, I was bringing in the PaymentSystem.php file which I had forgotton to bring in for the process3d method. This was the issue. Commented Jul 29, 2020 at 17:04
  • Hmm, does that mean you are calling "require_once" inside each function? If so, that may work, but its definitely not the best way to do it, the file should be autoloaded via composer and included once in the controller via a use statement like RequestGatewayEntryPointList Commented Jul 29, 2020 at 17:25

1 Answer 1

1

Found it 5 minutes after posting to stackoverflow... oops.

process3d was missing require_once DIR.'/../../Services/PaymentGateway/Gateway/PaymentSystem.php';

Adding this solved the issue.

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, I would expect such a class to be autoloaded, not manually required. Are you certain that use Services/PaymentGateway/Gateway/PaymentSystem.php or similar is not what you're after? (note that the path may be incorrect, youd need to check where it is exactly)
why would you be manually 'requiring' files when you have composer as the autoloader? just curious
While requiring manually solved the issue, it does feel like a workaround rather than a clean fix. However I am not sure what the issue is, or how to solve it otherwise. 2 points. 1. App/Services/PaymentGateway/Gateway/PaymentSystem.php is NOT a class, it is a php file containing many classes. 2 This is in the context of a Laravel project, which I believe requires PSR-4 compliance. My understanding is that, seeing as PaymentSystem.php is not a class, I can't write use App/Services/PaymentGateway/Gateway/PaymentSystem in my controller and access the classes within..?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.