Knowing that I have 3 tables:
people (id, name, surname)
$factory->define(SIMante\Personas::class, function ($faker) {
return [
'nombres' => $faker->firstName,
'apellidos' => $faker->lastName,
];
});
profiles (id, name)
$factory->define(SIMante\Perfiles::class, function ($faker) {
return [
'nombre' => $faker->unique()->randomElement($array = array ('Administrador','Usuario','Operario')),
];
});
users (id, id_personas (unique), name, mail, password, id_profiles)
I do not understand how to create the factory for the table since the column id_personas must be unique for each user.
here what I wear:
$factory->define(SIMante\User::class, function (Faker\Generator $faker) {
return [
'id_personas' => $faker->unique()->randomElement(SIMante\Perfiles::all()->id),
'nombre' => $faker->unique()->userName,
'correo' => $faker->unique()->safeEmail,
'clave' => bcrypt('123456'),
'id_perfiles' => SIMante\Perfiles::all()->random()->id,
];
});
but that throws me the following error
undefined property: illuminate \ database \ eloquent \ collection :: $ id
I have tried in several ways, but they all give me an error, although that is the one I see the most logic to use.