I am try to run “ServiceTableSeeder” table in database i got an error msg.
I try run “php artisan db:seed
“
Msg:
[symfonycomponent|DebugExceptionFetalErrorException]
cannot redeclare DatabaseSeeder::run()
DatabaseSeeder .php
<?php
use IlluminateDatabaseSeeder;
use IlluminateDatabaseEloquentModel;
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.
3
Answers
I think the problem is your
ServiceTableSeeder.php
file. You should make sure the class filename in this file isServiceTableSeeder
and notDatabaseSeeder
Considering that Service is a model you created, and that this model is inside the app folder, within the App namespace, try this:
Fix your ServiceTableSeeder.php header:
As you have moved your models to appmodels, you must declare that in each model file:
Models.php:
And in your seed file, use:
Are you using composer to autoload your files? If so, update your composer.json file to include your models location:
And finally, run this in your command line:
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
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