私は何が間違っているのか、および/またはこの状況を処理するより良い方法を理解しようとしています。
目標:
- 自分自身をユーザーとして挿入し、他の 200 人のユーザーをデータベースに挿入できるようにするため。
- 自分自身の静的データをプロファイル用の別のテーブルに挿入し、他のすべてのユーザーのランダム データをデータベース テーブルに挿入します。
- コンソールでシード ファイルを実行すると、[InvalidArgumentException] Unknown formatter "password" エラー メッセージが表示される理由を知りたいです。
ユーザーテーブルシーダー
<?php
use Illuminate\Database\Seeder;
use Laracasts\TestDummy\Factory as TestDummy;
use App\User;
class UsersTableSeeder extends Seeder {
public function run()
{
User::create([
'first_name' => 'Secret',
'last_name' => 'Secret',
'username' => 'secret',
'email' => 'secret',
'password' => 'secret',
]);
TestDummy::times(200)->create('App\User');
}
}
UserProfilesTableSeeder.php
<?php
use Illuminate\Database\Seeder;
use Laracasts\TestDummy\Factory as TestDummy;
use App\UserProfile;
class UserProfilesTableSeeder extends Seeder {
public function run()
{
UserProfile::create([
'user_id' => '1',
'avatar' => 'secret.jpg',
'bio' => 'This is just my personal biography!',
'address' => '1234 Secret Lane',
'city' => 'Secret',
'state' => 'Secret',
'postcode' => '12345',
'country' => 'United States',
'phone' => '123-456-7890',
'birthday' => '1988-09-04'
]);
TestDummy::create('App\UserProfile');
}
}
工場PHPファイル
<?php
$factory('App\User', [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'username' => $faker->userName,
'email' => $faker->email,
'password' => $faker->password
]);
$factory('App\UserProfile', [
'user_id' => 'factory:App\User',
'bio' => $faker->sentence(100),
'avatar' => $faker->imageUrl($width = 640, $height = 480),
'address' => $faker->optional($weight = 0.9)->address,
'city' => $faker->optional($weight = 0.9)->city,
'state' => $faker->optional($weight = 0.9)->state,
'postcode' => $faker->optional($weight = 0.9)->postcode,
'country' => $faker->optional($weight = 0.9)->country,
'phone' => $faker->optional($weight = 0.9)->phoneNumber,
'birthday' => $faker->optional($weight = 0.9)->dateTimeBetween('-40 years', '-18 years')
]);