I am new in laravel. whene I want to run seed by this command: php artisan db:seed, I get this error: [Symfony\Component\Debug\Exception\FatalThrowableError] Call to undefined function table()
my two seeder class:
1- GroupTableSeeder
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class GroupTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0');
DB::table('groups')->truncate();
$groups = [
['id' => 1, 'name' => 'Family', 'created_at' => new DateTime, 'updated_at' => new DateTime ],
['id' => 2, 'name' => 'Friends', 'created_at' => new DateTime, 'updated_at' => new DateTime ],
['id' => 3, 'name' => 'Customers', 'created_at' => new DateTime, 'updated_at' => new DateTime ],
['id' => 4, 'name' => 'CoWorkers', 'created_at' => new DateTime, 'updated_at' => new DateTime ],
['id' => 5, 'name' => 'Teachers', 'created_at' => new DateTime, 'updated_at' => new DateTime ]
];
DB:table('groups')->insert($groups);
}
}
2- ContactsTableSeeder
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Faker\Factory as Faker;
class ContactsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run() {
DB::table( 'contacts' )->truncate();
$faker = Faker::create();
$contacts = [];
foreach ( range( 1, 20 ) as $index ) {
$contacts[] = [
'name' => $faker->name,
'email' => $faker->email,
'phone' => $faker->phoneNumber,
'address' => "{$faker->streetName} {$faker->postcode} {$faker->city}",
'company' => $faker->company,
'created_at' => new DateTime,
'updated_at' => new DateTime,
];
}
DB::table( 'contacts' )->insert( $contacts );
}
}
and also my DatabaseSeeder class:
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(GroupTableSeeder::class);
$this->call(ContactsTableSeeder::class);
}
}
please help me solve it. thanks.
Aucun commentaire:
Enregistrer un commentaire