al ejecutar cesar@sisweb:/var/www/html/contact_manager$ php artisan db:seed
marca
Just wondering before "[ReflectionException] Class DatabaseSeeder does not exist" it was [ReflectionException] Class database\seeds\userTableSeeder does not exist
after trying all suggested putting namespace in it showed in the links and several call of commands "composer dump-autoload" and "php artisan clear-compiled" it suddenly become the Class DatabaseSeeder.
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
//Eloquent::unguard();
$this->call(GroupTableSeeder::class);
$this->call(ContactTableSeeder::class);
}
}
<?php
use Illuminate\Database\Seeder;
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' => 'Clients', 'created_at' => new DateTime, 'updated_at' => new DateTime],
];
DB::table('groups')->insert($groups);
}
}
<?php
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
class ContactTableSeeder 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);
}
}
No hay comentarios:
Publicar un comentario