Php 在laravel 8模型中,工厂给出了阵列误差
我是拉威尔初学者,想创建一个模型工厂<代码>调节工厂 我使用工厂和数据库播种机来制作它们 当我想给它播种子时,会出现错误:Php 在laravel 8模型中,工厂给出了阵列误差,php,factory,laravel-8,Php,Factory,Laravel 8,我是拉威尔初学者,想创建一个模型工厂调节工厂 我使用工厂和数据库播种机来制作它们 当我想给它播种子时,会出现错误: ErrorException:数组到字符串的转换 你能帮我修一下吗 这是我的规则: public function up() { Schema::create('regulations', function (Blueprint $table) { $table->id(); $table->uns
ErrorException:数组到字符串的转换
你能帮我修一下吗
这是我的规则:
public function up()
{
Schema::create('regulations', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->string('country');
$table->string('photo');
$table->string('short_description');
$table->longText('description');
$table->string('population');
$table->string('area');
$table->string('internet_penetration');
$table->string('national_currency');
$table->string('goverment');
$table->string('president');
$table->string('capital');
$table->string('language');
$table->float('economic_growth');
$table->string('dgtl_curr_lgs')
->comment('Legislation of digital currencies');
$table->string('dgtl_curr_tax')
->comment('Tax on digital currencies');
$table->string('dgtl_curr_pymt')
->comment('Payment status through digital currency');
$table->string('dgtl_curr_ntiol')
->comment('National Digital Currency');
$table->string('ICO');
$table->string('crpto_antimon_rules')
->comment('has Anti-money laundering rules for crypto or not');
$table->tinyInteger('status')
->comment('status is 1 when a regulation is active and it is 0 otherwise.')->nullable();
$table->foreign('user_id')->references('id')->on('users');
$table->rememberToken();
$table->softDeletes();
$table->timestamps();
});
}
这是我的调节工厂:
public function definition()
{
$users = User::pluck('id');
return [
'user_id'=>\App\Models\User::inRandomOrder()->first()->id,
'country'=>$this->faker->country,
'photo'=>$this->faker->text(10),
'description'=>$this->faker->sentences(50),
'short_description'=>$this->faker->sentence(50),
'population'=>$this->faker->numerify('########'),
'area'=>$this->faker->numerify('########'),
'internet_penetration'=>$this->faker->numerify('#########'),
'national_currency'=>$this->faker->word,
'goverment'=>$this->faker->words,
'president'=>$this->faker->name,
'capital'=>$this->faker->city,
'language'=>$this->faker->words,
'economic_growth'=>$this->faker->numerify('#'),
'dgtl_curr_lgs'=>$this->faker->sentence(1),
'dgtl_curr_tax'=>$this->faker->words,
'dgtl_curr_pymt'=>$this->faker->words,
'dgtl_curr_ntiol'=>$this->faker->words,
'ICO'=>$this->faker->word,
'crpto_antimon_rules'=>$this->faker->word,
];
}
我的监管模式是:
class Regulation extends Model
{
use HasFactory;
protected $fillable = [
'user_id' ,
'country' ,
'photo',
'short_description' ,
'description',
'area',
'internet_penetration',
'national_currency',
'goverment',
'president',
'capital',
'language',
'economic_growth',
'dgtl_curr_lgs',
'dgtl_curr_tax',
'dgtl_curr_pymt',
'dgtl_curr_ntiol',
'ICO',
'crpto_antimon_rules',
];
public function users(){
return $this->belongsTo(User::class);
}
}
我的错在哪里?感谢您的帮助:}您的错误是您正在使用
$this->faker->words
。应该是$this->faker->word
(不带“s”)
请参阅:因为您使用了$this->faker->words。这里,$this->faker->words(5)需要很多单词。因此,您需要通过传递值来设置字数,或者只能使用“$this->faker->word”