Skip to content
Advertisement

php artisan db:seed [ErrorException] count(): Parameter must be an array or an object that implements Countable

I am new to Laravel, i am seeding into a table called “area” in a database. Please this is an open source project I am learning with. Below is the code that gives the above error. Please don’t close my question, I have research anywhere I could for help.

   <?php

use IlluminateDatabaseSeeder;
use AppArea;
use CarbonCarbon;
class AreaTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Area::insert([
          ['name' => 'Dhanmondi', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()], 
        ]);
    }
}

I am seeding into the “area” table with the columns: name, created_at, updated_at, deleted_at. Can I be getting this error because I left the “deleted_at” column null? thanks for your time.

Advertisement

Answer

(Remember to mark this answer as the best answer) 🙂

So I put the solution here so that it’s visible to everyone :

Instead of insert try create, like :

Area::create([ 
'name' => 'Dhanmondi', 
'created_at' => Carbon::now(), 
'updated_at' => Carbon::now() 
]);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement