class_uses_recursive

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     function callTraitHook($name, $params = [])

    {

        foreach (class_uses_recursive($this->component) as $trait) {

            $method = $name.class_basename($trait);



            if (method_exists($this->component, $method)) {
<?php     function skip()

    {

        return ! in_array(WithPagination::class, class_uses_recursive($this->component));

    }



    function boot()
<?php         $this->component->paginators[$pageName] = $this->resolvePage($queryStringDetails['as'], $defaultPage);



        $shouldSkipUrlTracking = in_array(

            WithoutUrlPagination::class, class_uses_recursive($this->component)

        );



        if ($shouldSkipUrlTracking) return;
<?php         if (method_exists($component, 'queryString')) $componentQueryString = invade($component)->queryString();

        elseif (property_exists($component, 'queryString')) $componentQueryString = invade($component)->queryString;



        return $this->queryString = collect(class_uses_recursive($class = $component::class))

            ->map(function ($trait) use ($class, $component) {

                $member = 'queryString' . class_basename($trait);
<?php     public function shouldBypassExceptionForLivewire(\Throwable $e, $obLevel)

    {

        $uses = array_flip(class_uses_recursive($e));



        return (
<?php     public function dispatchNow($command, $handler = null)

    {

        $uses = class_uses_recursive($command);



        if (in_array(InteractsWithQueue::class, $uses) &&

            in_array(Queueable::class, $uses) &&
<?php     {

        parent::__construct();



        if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) {

            $this->addTestOptions();

        }
<?php         $info = $this->type;



        if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) {

            if ($this->handleTestCreation($path)) {

                $info .= ' and test';

            }
<?php     protected function isPrunable($model)

    {

        $uses = class_uses_recursive($model);



        return in_array(Prunable::class, $uses) || in_array(MassPrunable::class, $uses);

    }
<?php         $instance = new $model;



        $count = $instance->prunable()

            ->when(in_array(SoftDeletes::class, class_uses_recursive(get_class($instance))), function ($query) {

                $query->withTrashed();

            })->count();
<?php             return $this->macroCall($method, $parameters);

        }



        if ($method === 'trashed' && in_array(SoftDeletes::class, class_uses_recursive($this->modelName()))) {

            return $this->state([

                $this->newModel()->getDeletedAtColumn() => $parameters[0] ?? Carbon::now()->subDay(),

            ]);
<?php         $total = 0;



        do {

            $total += $count = in_array(SoftDeletes::class, class_uses_recursive(get_class($this)))

                        ? $query->forceDelete()

                        : $query->delete();
<?php         static::$traitInitializers[$class] = [];



        foreach (class_uses_recursive($class) as $trait) {

            $method = 'boot'.class_basename($trait);



            if (method_exists($class, $method) && ! in_array($method, $booted)) {
<?php         $this->load(collect($this->relations)->reject(function ($relation) {

            return $relation instanceof Pivot

                || (is_object($relation) && in_array(AsPivot::class, class_uses_recursive($relation), true));

        })->keys()->all());



        $this->syncOriginal();
<?php         $total = 0;



        $this->prunable()

            ->when(in_array(SoftDeletes::class, class_uses_recursive(get_class($this))), function ($query) {

                $query->withTrashed();

            })->chunkById($chunkSize, function ($models) use (&$total) {

                $models->each->prune();