Search code examples
phpdatabaselaravellaravel-4seeding

Laravel4 Database Seeder error - Call to undefined method SeedDummyOrders::setContainer()


I have two tables in my database:

  • order_header
  • order_details

I need some dummy data, so I created the following SeedDummyOrders class:

<?php

class SeedDummyOrders {

    public function run()
    {
        DB::table('order_details')->delete();
        DB::table('order_header')->delete();

        $inventory_ids = range(1, 10);

        for ($i = 1; $i <= 5; $i++)
        {
            $order = new \OrderHeader;
            $order->owner_id = 1;
            $order->order_number = '100' . $i;
            $order->delivery_type = 'Standard';
            $order->order_status = 'Received';
            $order->address_line1 = $i . ', Some Street';
            $order->city = 'London';
            $order->postcode = 'ABC D' . $i;
            $order->country_code = 'GB';
            $order->country_name = 'Great Britain';
            $order->contact_name = 'Mr Person ' . $i;
            $order->contact_email = 'contact' . $i . '@mail.com';
            $order->save();

            $rand_keys = array_rand($inventory_ids, mt_rand(1, 5));
            $detail_inventory_ids = [];
            foreach ($rand_keys as $k)
                $detail_inventory_ids[] = $inventory_ids[$k];
            foreach ($detail_inventory_ids as $detail_inventory_id)
            {
                $detail = new \OrderDetail;
                $detail->order_id = $order->id;
                $detail->inventory_id = $detail_inventory_id;
                $detail->qty_ordered = mt_rand(1, 10);
                $detail->qty_picked = 0;
                $detail->qty_packed = 0;
                $detail->qty_dispatched = 0;
                $detail->save();
            }
        }
    }

}

I ran the seeder like this: php artisan db:seed --class=SeedDummyOrders

When I do, I get the following errors:

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to undefined method SeedDummyOrders::setContainer()","file":"C:\wamp\www\MY_PROJECT\vendor\laravel\framework\src\Illuminate\Database\Console\SeedCommand.php","line":69}}

enter image description here

Any ideas what this is about and how do you fix it?


Solution

  • Okay, I have a silly mistake. I forgot to extend this class with DatabaseSeeder.

    Now this works.