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

2

5

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?

Ganof answered 26/2, 2015 at 12:48 Comment(0)
G
14

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

Now this works.

Ganof answered 26/2, 2015 at 12:48 Comment(0)
M
2

I had the same issue. Once I ran composer dumpautoload I got the following message:

vagrant@vagrant:/vagrant/getrileynow$ composer dumpautoload
Generating autoload files
Warning: Ambiguous class resolution, "GenerateEmailFilters" was found in both "/vagrant/project/database/migrations/2017_02_26_033525_generate_email_filters.php" and "/vagrant/project/database/seeds/GenerateEmailFilters.php", the first will be used.

After renaming the seeder file to something else, I was able to run the migration.

Mydriatic answered 26/2, 2017 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.