Tengo un problema al usar Faker
para migrar datos a mi tabla. Quiero importar 50 fakes
nombres y countrys a mi tabla. Cuando ejecuto el comando db:seed
no hace un seed
de nada.
Propiedad model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Propiedad extends Model{
protected $table = 'Propiedades';
protected $fillable = ['name', 'pais'];
}
PropiedadesTableSeeder
<?php
use Illuminate\Database\Seeder;
use Faker\Factory as Faker;
use Illuminate\Support\Facades\DB;
class PropiedadesTableSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run() {
factory(App\Propiedad::class, 50)->create()->each(function($u){
$u->posts()->save(factory(App\Propiedad::class)->make());
});
}
}
Table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class PropiedadesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(){
Schema::create('propiedades', function (Blueprint $table) {
$table->increments('id');
$table->string('nombre');
$table->integer('barrio');
$table->integer('ciudad');
$table->integer('pais');
$table->boolean('cochera');
$table->float('ambientes');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('propiedades');
}
}
databaseseeder
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run() {
// $this->call(DatabaseSeeder::class);
// $this->call(PropiedadesTableSeeder::class);
}
}
factory
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\User::class, function (Faker\Generator $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});
$factory->define(App\Propiedad::class, function ($faker) {
return [
'nombre' => $faker->name,
'pais' => $faker->unique()->country,
];
});