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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.