-1

So i have a trait, let's name it TraitTwo It looks like this:

<?php

namespace App\Traits;

use App\Models\Using1;
use App\Models\Using2;

trait TraitTwo
{
    public function MyFuncTwo() {
        code..
        code..
    }
}

I want to use this trait in another trait, let's name this one TraitOne It looks like this:

<?php

namespace App\Traits;

use App;
use App\Models\UsingOne;
use App\Models\UsingTwo;
use App\Models\UsingThree;
use App\Models\UsingFour;
use Illuminate\Support\Facades\UsingFive;
use UsingSix;
use UsingSeven;

trait TraitOne
{
    use TraitTwo;
    public function MyFuncOne() {
        TraitTwo::MyFuncTwo();
    }
}

Except this is not working, I keep getting the following error:

Trait 'App\Traits\TraitTwo' not found

2 Answers 2

2

Turns out I forgot the .php after the filename..

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I was stuck on the same thing for ages, haha thanks!
1

You should reset composer cache after creating a Trait, in your console :

composer dump-autoload

Then, try again

1 Comment

Maybe this proves usefull for you.."autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.