4

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.

user2094178
9,47410 gold badges45 silver badges70 bronze badges
asked Apr 19, 2015 at 8:19
6
  • 1
    Try doing a composer dump. Commented Apr 19, 2015 at 8:56
  • I try "composer dump-autoload" but same error msg Commented Apr 19, 2015 at 12:05
  • 1
    I’m interested in your services. Can you get me on the first page of Google for "web design"? Commented Apr 19, 2015 at 16:26
  • @GobinathMahalingam You genuinely think you can get me to the top of Google for the phrase "web design"? 😄 Commented Apr 20, 2015 at 8:37
  • @GobinathMahalingam White hot SEO techniques? I’m sold! Commented Apr 20, 2015 at 9:28

3 Answers 3

2

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:

<?php
use Illuminate\Database\Seeder;
use App\Service;
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.'
 )
 );
 }
}

As you have moved your models to app\models, you must declare that in each model file:

Models.php:

 namespace App\Models;

And in your seed file, use:

 use App\Models\Service.php;

Are you using composer to autoload your files? If so, update your composer.json file to include your models location:

"autoload": {
 "classmap": [
 "database",
 "app/Models"
 ],
 "psr-4": {
 "App\\": "app/"
 }
},

And finally, run this in your command line:

composer dump-autoload
Qazi
5,1458 gold badges44 silver badges63 bronze badges
answered Apr 19, 2015 at 14:33

4 Comments

i try your step but i got "[symfony\component|Debug\Exception\FetalErrorException] class 'Service' Not found . Pls guide me
@GobinathMahalingam I believe that you need to declare the namespace of the model. I included that in the answer.
@authur samarcos: I'm using laravel new version . I created models folder inside App folder. And created service model page. I try "use App\service;" and also "use App\models \Services" but I got same error msg
I think I make mistake to create models pls guide me
2

I think the problem is your ServiceTableSeeder.php file. You should make sure the class filename in this file is ServiceTableSeeder and not DatabaseSeeder

answered Apr 19, 2015 at 9:19

1 Comment

I added my "ServiceTableSeeder.php" pls guide me
2

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

answered Sep 28, 2016 at 0:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.