4

I have a custom class I added to Classes, invoice.php within the Classes folder (\App\Classes).

When using a controller function, I can't execute a static function, says Class not found. I have the namespace and use set up like any other classes, similar to Helpers.php.

Class:

<?php namespace App\Classes;

class invoice {
//
}
?>

Contoller:

<?php namespace App\Http\Controllers;

use App\Classes\invoice;

class CustomerController extends Controller {
//
}
?>

Error:

FatalErrorException in CustomerController.php line 284:
Class 'App\Http\Controllers\invoice' not found

I've been stuck here for two hours and I don't understand what I'm doing wrong. Composer is using psr-4 and the Helpers.php file works fine, but my custom class file doesn't.

Thanks

1
  • the "i" in invoice is lowercase on your class name. Should be uppercase. Commented May 22, 2015 at 1:18

1 Answer 1

3

To follow PSR-4 you need to have your class names initial-caps. The "i" should be capitalized here:

<?php namespace App\Classes;

class Invoice {
   //
}

Also fix your use as well. Then when Invoice is used in your controller, it will pick up the correct namespace to use for resolving that class. What's happening currently is it is not finding a matching reference in your use section, so it assumes it is in the same namespace of the controller class that calls it.

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

1 Comment

I have a similar issue, but my class name is in upper-camel-case. I have a class class InvoiceGenerator in app/Classes/InvoiceGenerator folder. And in my controller, I am using use App\Classes\InvoiceGenerator\InvoiceGenerator; Any idea?

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.