Which fields are missing data? On what table?
Aug 1, 2022
7
Level 1
Seeder not giving enough data
I'm trying to make fake data, so I tried this with a for loops, but it does not give all the fields data. Could someone please tell me a way so I can give all my fields data connected with the right foreign key.
Somehow I can not wrap my head around it, any help would be highly appreciated.
$this->faker = Faker::create();
DB::table('users')->insert([
'username' => "username",
'role' => "admin",
'password' => 'password',
'pin' => 'pincode',
]);
for ($i = 1; $i <= 19; $i++) {
DB::table('main_gallery_names')->insert([
'user_id' => 1,
'title' => $this->faker->word,
]);
for ($d = 1; $d <= 3; $d++) {
DB::table('sub_gallery_names')->insert([
'main_gallery_name_id' => $i,
'title' => $this->faker->word,
'theme' => 'dark',
]);
for ($x = 1; $x <= 2; $x++) {
DB::table('sliders')->insert([
'sub_gallery_name_id' => $d,
'title' => 'Test image title ',
'text' => 'Test image text ',
]);
for ($l = 1; $l <= 2; $l++) {
DB::table('galleries')->insert([
'slider_id' => $x,
'image' => "mountains.jpeg",
'video' => "",
]);
}
}
}
}
Level 1
This is what I was trying to do sorry for the bad explanation. Thank you guys for the help and I'm sorry for wasting your time.
$this->faker = Faker::create();
DB::table('users')->insert([
'username' => "username",
'role' => "admin",
'password' => 'password',
'pin' => 'pincode',
]);
for ($i = 1; $i <= 19; $i++) {
DB::table('main_gallery_names')->insert([
'user_id' => 1,
'title' => $this->faker->word,
]);
}
$MGN = MainGalleryName::all();
foreach ($MGN as $key => $item) {
for ($d = 1; $d <= 3; $d++) {
DB::table('sub_gallery_names')->insert([
'main_gallery_name_id' => $item->id,
'title' => $this->faker->word,
'theme' => 'dark',
]);
}
}
$SGN = SubGalleryName::all();;
foreach ($SGN as $key => $item) {
for ($x = 1; $x <= 3; $x++) {
DB::table('sliders')->insert([
'sub_gallery_name_id' => $item->id,
'title' => 'Test image title ',
'text' => 'Test image text ',
]);
}
}
$slider = Slider::all();
foreach ($slider as $key => $item) {
for ($l = 1; $l <= 4; $l++) {
DB::table('galleries')->insert([
'slider_id' => $item->id,
'image' => "mountains.jpeg",
'video' => "",
]);
}
}
Please or to participate in this conversation.