@getupkid203 Make sure you have imported the namespaced UserObserver into your User class.
For example:
use App\Observers\UserObserver;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Howdy all, I've got a Laravel 11 project. My PHP Version is 8.3. Using Homestead on Windows.
I can't get any PHP8 attributes to work as expected. For example:
#[ObservedBy([UserObserver::class])]
class User extends Authenticatable
{
//
}
My UserObserver::class definitely exists. When I create a UserFactory, the observer is never called.
However, if I register the Observer manually via AppServiceProvider, it works perfectly i.e.:
public function boot(): void
{
User::observe(UserObserver::class);
}
I was under the impression that as of PHP8.0, these attributes should work. Is there something I may be missing?
Please or to participate in this conversation.