It seems your trait does not start with a capital C but is actually named ./app/Traits/commonTrait.php and autoloading doesn't work. Try renaming it to CommonTrait.php
Trait Not Found (Laravel v8.39)
Just upgraded laravel from 8.32 to 8.39 and ran into a problem.
Everything works as expected on localhost but on live server I'm getting a trait not found error.
production.ERROR: Trait 'App\Traits\CommonTrait' not found {"userId":2,"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Trait 'App\Traits\CommonTrait' not found at /home/***/***/app/Http/Livewire/Panels/ForumThread.php:16
Dumping autoload presents me with the following notice:
Class App\Traits\CommonTrait located in ./app/Traits/commonTrait.php does not comply with psr-4 autoloading standard. Skipping.
In forumThread.php I'm calling the trait as follows:
use App\Traits\CommonTrait;
Inside the class:
use CommonTrait;
Trait Directory:
app/Traits
Trait File Name:
CommonTrait.php
Trait Class Name:
trait CommonTrait
{
etc......
}
Any ideas why this is not working in production and works fine on localhost?
@atomcoder Try renaming the file. If you’re using Git, you’ll need to use Git to do this:
git mv app/Traits/commonTrait.php app/Traits/CommonTrait.php
If the file name (including casing) doesn’t match the namespace and class name, then Composer won’t include it when building the autoload map, which is why the trait is not getting found.
Please or to participate in this conversation.