Laravel :"php artisan db:seed" doesn't work

CodeMan picture CodeMan · Apr 19, 2015 · Viewed 8.4k times · Source

I am try to run "ServiceTableSeeder" table in database i got an error msg.

I try run "php artisan db:seed"

Msg:

[symfony\component|Debug\Exception\FetalErrorException]
cannot redeclare DatabaseSeeder::run()

DatabaseSeeder .php

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
     public function run()
     {
         Eloquent::unguard();
         $this->call('ServiceTableSeeder');

     }

}

ServiceTableSeeder.php

<?php

class ServiceTableSeeder extends Seeder {

  public function run()
  {
    Service::create(
      array(
        'title' => 'Web development',
        'description' => 'PHP, MySQL, Javascript and more.'
      )
    );

    Service::create(
      array(
        'title' => 'SEO',
        'description' => 'Get on first page of search engines with our help.'
      )
    );

  }
}

how to fix this issue .i am new in laravel anyone please guide me.

Answer

ankit patel picture ankit patel · Sep 28, 2016

For those who are facing the same issue, confirm your APP_ENV variable from .env file cause Laravel don't let us to run db:seed if we set

'APP_ENV = Production'

for the sake of database records.

So, make sure you set value of APP_ENV to 'staging' or 'local' and then run php artisan db:seed