I create Service Plugin in October CMS. I have 2 repeaters fields (packages, postman). I use Faker Plugin to Insert dummy data in the database but has an error
Invalid argument supplied for foreach()
This is my code for seed
<?php namespace Sepehr\Service\Updates;
use Sepehr\Service\Models\Service;
use Faker;
use October\Rain\Database\Updates\Seeder;
class SeedAllTable extends Seeder
{
public function run()
{
$faker = Faker\Factory::create();
$service = new Service();
$service->user_id = 1;
$service->manager_id = 1;
$service->sender_postal_code = $faker->postcode();
$service->sender_address = $faker->address();
$service->status_id = $faker->numberBetween(1, 6);
foreach ($service->packages as $package) {
$package['receiver_postal_code'] = $faker->postcode();
$package['receiver_address'] = $faker->address();
$package['weight_id'] = $faker->numberBetween(1, 3);
$package['post_type_id'] = $faker->numberBetween(1, 3);
$package['distribution_time_id'] = $faker->numberBetween(1, 3);
$package['special_services_id'] = $faker->numberBetween(1, 3);
$package['price'] = 0;
$package['package_type_id'] = $faker->numberBetween(1, 3);
$package['insurance_type_id'] = $faker->numberBetween(1, 3);
}
$service->save();
$service->packages
this is not working because you want to create service,$service->packages
this will work when already service will be there and It will contain packages. – Chirag Patel