如何在Laravel模型中使用特征?

Hello i'm laravel beginner

I want to make trait and use it in my model but at run time i got error that the trait is not found

my trait :

namespace App;
use Illuminate\Support\Facades\Schema;

trait GeneralModel
{
    public static function testStaticFunction()
    {
        dd('test');
    }
}

my model :

namespace App;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use GeneralModel;
}

my controller

namespace App\Http\Controllers;

use App\Comment;

class SearchController extends Controller
{
    public function find()
    {
        Comment::testStaticFunction();
    }
}

error received

Trait 'App\GeneralModel' not found

Please check the GeneralModel.php in app folder. And execute the below command in your project root path.

php artisan dump-autoload

You Have to Use

Composer dump-autoload

In Your command line

hope it's help

In composer.json add this:

  "autoload"    : {
"classmap": [
  "database/seeds",
  "database/factories"
],
"files"   : [

  "app/GeneralModel.php" // <----------- ADD THIS 
],
"psr-4"   : {
  "App\\": "app/"
}},

Then run composer dump-autoload