cargar seeder en codeigniter 4 code example

Example 1: codeigniter 4 db seed

<?php namespace App\Database\Seeds;

class TestSeeder extends \CodeIgniter\Database\Seeder
{
        public function run()
        {
                $this->call('UserSeeder');
                $this->call('CountrySeeder');
                $this->call('JobSeeder');
        }
}

Example 2: codeigniter 4 db seed

<?php namespace App\Database\Seeds;

class SimpleSeeder extends \CodeIgniter\Database\Seeder
{
        public function run()
        {
                $data = [
                        'username' => 'darth',
                        'email'    => '[email protected]'
                ];

                // Simple Queries
                $this->db->query("INSERT INTO users (username, email) VALUES(:username:, :email:)",
                        $data
                );

                // Using Query Builder
                $this->db->table('users')->insert($data);
        }
}

Tags:

Php Example