The class_uses_recursive function returns all traits used by a class, including traits used by all of its parent classes:
<?php $traits = class_uses_recursive(App\Models\User::class);
<?php     protected function addFactoryTrait($modelClass)

    {

        $traits = class_uses_recursive($modelClass);

        if (is_array($traits) && in_array('Illuminate\\Database\\Eloquent\\Factories\\HasFactory', $traits)) {

            return;

        }