Laravel 8, Model factory class not found

前端 未结 6 1436
孤街浪徒
孤街浪徒 2021-01-17 16:47

so when using the new model factories class introduced in laravel 8.x, ive this weird issue saying that laravel cannot find the factory that corresponds to the model. i get

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 17:31

    If you upgraded to 8 from a previous version you are probably missing the autoload directive for the Database\Factories namespace in composer.json:

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    

    You can also remove the classmap part, since it is no longer needed.

    Run composer dump after making these changes.

    Laravel 8.x Docs - Upgrade Guide - Database - Seeder and Factory Namespace

提交回复
热议问题