Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AtomCoder's avatar

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?

0 likes
4 replies
madsem's avatar

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

AtomCoder's avatar

I noticed that too, but the file name is actually named CommonTrait.php

martinbean's avatar
Level 80

@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.

1 like
AtomCoder's avatar

That worked perfectly. It was indeed that the file name in the folder was commonTrait.php. Thank you for your help.

1 like

Please or to participate in this conversation.