gpt4 book ai didi

php - Laravel 8,找不到模型工厂类

转载 作者:行者123 更新时间:2023-12-03 11:20:54 24 4
gpt4 key购买 nike

因此,当使用在laravel 8.x中引入的新模型工厂类时,就说明了这个奇怪的问题,即laravel无法找到与该模型相对应的工厂。我得到这个错误

PHP Error:  Class 'Database/Factories/BusinessUserFactory' not found in .....

我跟随laravel文档,我不知道发生了什么
这是 BusinessUser
<?php

namespace App;

use Database\Factories\BusinessUserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BusinessUser extends Model
{
use HasFactory;
}

和工厂
<?php

namespace Database\Factories;

use App\BusinessUser;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class BusinessUserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = BusinessUser::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => "dsfsf"
];
}
}


任何想法或线索,我们将不胜感激。

最佳答案

如果从以前的版本升级到8,则可能会丢失Database\Factoriescomposer.json命名空间的autoload指令:

"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
您也可以删除 classmap部分,因为不再需要它。
进行这些更改后,运行 composer dump
Laravel 8.x Docs - Upgrade Guide - Database - Seeder and Factory Namespace

关于php - Laravel 8,找不到模型工厂类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63943758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com