I am trying to create a Seeder called users to be able to modulate the seeds for each different table and have the project better organized. The problem is that when I use the command:
php artisan db:seed
Only execute the "DatabaseSeeder.php" even if you have created another.
I have tried to create it manually and using the console with the command:
php artisan make:seeder UsersTable
The code I have in seed "UserTable" is:
<?php
use Illuminate\Database\Seeder;
use App\User;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
//Array users test
private $users= array(
array( 'name' => 'albert',
'email' => '[email protected]',
'password' => '1234',
'role' => 1),
array( 'name' => 'test',
'email' => '[email protected]',
'password' => 'test',
'role' => 2),
array( 'name' => 'test2',
'email' => '[email protected]',
'password' => 'test2',
'role' => 2),
array( 'name' => 'test3',
'email' => '[email protected]',
'password' => 'test3',
'role' => 2),
);
//contador de filas creadas
private $rows = 0;
public function userSeed() {
//
for($i=0;$i<count($this->users);$i++){
//$this->command->info($this->users[$i].' Users cargados!');
$this->command->info($this->users[$i]['email']);
$this->command->info($this->users[$i]['password']);
$user_seed = new User();
$user_seed->name = $this->users[$i]['name'];
$user_seed->email = $this->users[$i]['email'];
$user_seed->password = bcrypt($this->users[$i]['password']);
$user_seed->role = $this->users[$i]['role'];
$user_seed->save();
$this->rows++;
}
}
//function run
public function run()
{
self::userSeed();
$this->command->info($this->rows.' :Users cargados!');
}
}
If I have the code in "DatabaSeeder.php" it works perfectly.
Could you throw me some light?
Thanks in advance!.