Laravel 8, Model factory class not found

前端 未结 6 1440
孤街浪徒
孤街浪徒 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:16

    I'm in the process of migrating from laravel 7 to 8.

    After banging my head against the wall for a while and looking at the source code, I saw that you can optionally override what factory class gets called for a model using the newFactory method on the model.

    I also then noticed that it IS in the documentation (https://laravel.com/docs/8.x/database-testing#creating-models) - I just didn't understand what it meant the first time I read it. Now I do.

    I solved this by the following:

    After this change, my tests passed as expected.

提交回复
热议问题