Estou usando o ModelFactory
padrão do Laravel 5 já há algum tempo, e estava indo tudo ok, mas de uns dias pra cá parou de gerar dados da biblioteca faker
para algumas tabelas, apesar de continuar normalmente para outras.
Quando rodo php artisan db:seed -vvv
com as definições abaixo, a tabela client
é preenchida corretamente, com todos os valores, e a tabela email
acaba com 100 linhas de valores default ou vazios.
Alguma ideia de por onde começar a debugar isso?
database/factory/ModelFactory.php (default)
$factory->define(App\Client::class, function ($faker) {
$origins = DB::table('origin')->lists('id');
$methods = DB::table('entry_method')->lists('id');
$image = str_replace('public', '', $faker->image('public/img', '100', '100', 'cats'));
return [
'name' => $faker->firstName,
'middlename' => $faker->lastName,
'lastname' => $faker->lastName,
'birthday' => $faker->date(),
'type' => $faker->randomElement(array('nao-associado','patrimonial','cooperador','coletivo','entidade','emerito','individual')),
'associate_code' => $faker->randomNumber(),
'identification' => str_random(20),
'identification_type' => $faker->randomElement(array('rg','cpf','cnh','passaporte','social-security','outro')),
'language' => $faker->randomElement(array('pt','en')),
'foreigner' => $faker->boolean(),
'image' => $image,
'vip' => $faker->numberBetween(0,1),
'id_origin' => $faker->randomElement($origins),
'id_entry_method' => $faker->randomElement($methods),
];
});
$factory->define(App\Email::class, function ($faker) {
$clients = DB::table('client')->lists('id');
return [
'email' => $faker->companyEmail,
'type' => $faker->randomElement(array('pessoal','comercial')),
'id_client' => $faker->randomElement($clients),
];
});
database/seeds/DatabaseSeeder.php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Connection;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
DB::statement('SET FOREIGN_KEY_CHECKS=0');
factory('App\Client', 100)->create();
factory('App\Email', 100)->create();
// create
DB::statement('SET FOREIGN_KEY_CHECKS=1');
Model::reguard();
}
}
app/Email.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Email extends Model
{
public $domains;
public $timestamps = false;
protected $table = 'email';
protected $fillable = ['email', 'type', 'mailchimp_id', 'id_client'];
}
EDIT: migrations
Schema::create('client', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 50);
$table->string('middlename', 50)->nullable();
$table->string('lastname', 50);
$table->date('birthday')->nullable();
$table->enum('type', ['nao-associado','patrimonial',
'cooperador','coletivo',
'entidade','emerito',
'individual'])->default('nao-associado');
$table->string('associate_code', 45)->nullable(); // codigo_socio
$table->string('identification'); // documento identidade
$table->enum('identification_type', ['rg','cpf','cnh','passaporte','social-security','outro']); // codigo_socio
$table->enum('language', ['pt','en'])->default('pt');
$table->boolean('foreigner')->default(false);
$table->string('password', 255)->nullable(); // documento identidade
$table->string('image', 255); // foto
$table->boolean('vip')->default(false);
// Foreign keys
$table->integer('id_entry_method')->unsigned();
$table->integer('id_origin')->unsigned();
$table->integer('id_client')->unsigned()->nullable();
$table->foreign('id_entry_method')->references('id')->on('entry_method');
$table->foreign('id_origin')->references('id')->on('origin');
$table->foreign('id_client')->references('id')->on('client');
$table->timestamps();
$table->softDeletes();
});
Schema::create('email', function(Blueprint $table)
{
$table->increments('id');
$table->string('email', 50);
$table->enum('type', ['pessoal','comercial']);
$table->string('mailchimp_id', 100);
$table->integer('id_client')->unsigned();
$table->foreign('id_client')->references('id')->on('client');
});
\DB::
\DB::
mas acho pouco provável que seja isso porque as chamadas pra DB funcionam emclient