Seeding Data - Multiple inserts in one statement
Created 6 years ago by garethshaw

Hi all Lots of questions, finally getting going on this project and I'm running into lots of little issues. So I want to seed maybe 300 records, I've created an array which I loop over, however this means I'm doing a single insert 300 times, can I create an insert statement and do them all in one go?

    /**
     * Makes data array
     */
    $makes_data = array(
        array(
            'name' => 'DJI Innovations',
            'description' => 'As the market leader in easy-to-fly drones and aerial photography systems, DJI quadcopters have become the standard in consumer drone technology',
        ),
    );

    /**
     * Loop over each of the Makes
     */
    foreach ($makes_data as $make_data) {
        // grab the name name
        $make_name = trim($make_data['name']);

        // slugify it
        $make_name = trim(str_replace("+", " plus", $make_name));
        $make_name_slugified = trim($this->str->slug($make_name, "-"));

        // add each one in to the database
        $this->makes->create(
            [
                'en' => [
                    "name" => $make_name,
                    "description" => trim($make_data['description']),
                ],
                'slug' => $make_name_slugified,
                'enabled' => true,
            ]
        );
    }