I'm having issues seeding my DB all of a sudden using Laravel 5.1's Model factories. I had this going just fine and now it isn't working anymore.
I tried using Carbon date formats and still am getting the error?
Here is the error:
vagrant@homestead:~/Code/jobboard$ php artisan migrate:refresh --seed
Rolled back: 2015_06_10_162857_create_jobs_table
Rolled back: 2015_06_10_162653_create_users_table
Rolled back: 2015_06_10_153026_create_job_types_table
Rolled back: 2015_06_10_152237_create_job_categories_table
Rolled back: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2015_06_10_152237_create_job_categories_table
Migrated: 2015_06_10_153026_create_job_types_table
Migrated: 2015_06_10_162653_create_users_table
Migrated: 2015_06_10_162857_create_jobs_table
Seeded: UsersTableSeeder
[InvalidArgumentException]
A four digit year could not be found
Data missing
Here is my factory I set up:
$factory->define('App\Job', function ($faker) {
return [
'cat_name' => $faker->word,
'title' => $faker->sentence,
'location' => $faker->city,
'remote' => $faker->boolean($chanceOfGettingTrue = 50),
'type_name' => $faker->word,
'description' => $faker->paragraph,
'how_to_apply' => $faker->paragraph,
'company_name' => $faker->word,
'website' => $faker->url,
'logo' => $faker->imageUrl($width = 50, $height = 50),
'featured' => $faker->boolean($chanceOfGettingTrue = 50),
'expires_at' => $faker->dateTime($max = 'now')->format('Y-m-d h:i:s'),
'agree_terms' => $faker->boolean($chanceOfGettingTrue = 90),
'user_id' => $faker->numberBetween($min = 1, $max = 10),
'cat_id' => $faker->numberBetween($min = 1, $max = 9),
'type_id' => $faker->numberBetween($min = 1, $max = 5),
];
});
Here is my model:
class Job extends Model
{
protected $table = 'jobs';
protected $primaryKey = 'job_id';
protected $fillable = [
'job_id',
'cat_name',
'title',
'location',
'remote',
'type_name',
'description',
'how_to_apply',
'company_name',
'website',
'logo',
'featured',
'expires_at',
'agree_terms',
'user_id',
'cat_id',
'type_id',
];
}
Not sure if anyone else will find this helpful but wanted to post the solution to my own problem in case anyone made the same mistake.
The issue was this line:
factory( \App\Task::class, 10 )->create( [ 'user_id', $user->id ] );
If you noticed, I have a comma
,
when it should be an assignment operator=>
.Should be:
factory( \App\Task::class, 10 )->create( [ 'user_id' => $user->id ] );