Samuel Thomas
Samuel Thomas

Reputation: 133

Error while applying a seeder in laravel

Here is my code that intends to seed the includes table:

<?php

use Illuminate\Database\Seeder;
use App\Include;

class IncludesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
      $faker = Faker\Factory::create();

      for ($i=1; $i < 12; $i++) {
          $include = [
              'name' => $faker->words(2, true),
              'price' => $faker->numberBetween(20000,  2000000),
              'product_id' => $i,
          ];
          Include::create($include);
      }
    }
}

But when I attempt to run the seeder via artisan I get this error:

[Symfony\Component\Debug\Exception\FatalThrowableError]                      
  Parse error: syntax error, unexpected 'Include' (T_INCLUDE), expecting iden 
  tifier (T_STRING) or '{'

I can't figure out what is missing, anybody with an idea please!

Upvotes: 0

Views: 439

Answers (1)

inet123
inet123

Reputation: 774

PHP don't allow you to name a class Include, change the name of the model and it should work.

Please notice that if you change the name of the model you either need to change the name of table as well or use the protected var table to override the convention.

class NameOfClass
{
    protected $table = "includes";

}

Upvotes: 1

Related Questions