1

I have a problem with my PHP Exception class in Laravel.

I am creating a class in \App\Services folder.

I have created some test code where I have the following:

if (!in_array($variables, $validParameters)) {
        throw new Exception("Invalid parameter types: ".str_replace(")(", ", ", $variables));
    }

And I get the following error:

Class 'App\Services\Exception' not found

How I can fix this problem?

2 Answers 2

3

If your class is namespaced then you need to scape the Exception class name to let PHP know you are using an exception from the global namespace and not from your current namespace (App\Services).

  throw new \Exception(...)

Note the "\" character before the class name

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

Comments

0

try this in your services file

use Exception;

1 Comment

That doesn't help, same problem

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.