Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.1模型工厂种子错误_Php_Database_Laravel_Seeding - Fatal编程技术网

Php Laravel 5.1模型工厂种子错误

Php Laravel 5.1模型工厂种子错误,php,database,laravel,seeding,Php,Database,Laravel,Seeding,我在使用Laravel 5.1的模型工厂时突然遇到了问题。我的工作进行得很顺利,但现在已经不起作用了 我尝试使用碳日期格式,但仍然得到错误 以下是错误: 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 Roll

我在使用Laravel 5.1的模型工厂时突然遇到了问题。我的工作进行得很顺利,但现在已经不起作用了

我尝试使用碳日期格式,但仍然得到错误

以下是错误:

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   
这是我建立的工厂:

$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),        
    ];
});
这是我的模型:

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',
];


}

不确定是否有其他人会觉得这有帮助,但想发布我自己问题的解决方案,以防有人犯同样的错误

问题是这一行: factory\App\Task::class,10->create['user_id',$user->id]

如果您注意到,我有一个逗号,它应该是赋值运算符=>

应该是:
factory\App\Task::class,10->create['user\u id'=>$user->id]

不确定是否有其他人会觉得这有帮助,但想发布我自己问题的解决方案,以防有人犯同样的错误

问题是这一行: factory\App\Task::class,10->create['user_id',$user->id]

如果您注意到,我有一个逗号,它应该是赋值运算符=>

应该是:
factory\App\Task::class,10->create['user\u id'=>$user->id]

我偶然发现了这个,因为我也犯了同样的错误。错误日志显示它正试图从字符串用户id创建一个Carbon实例。我完全迷路了…偶然发现这个,因为我得到了相同的错误。错误日志显示它正在尝试从字符串用户id创建Carbon实例。我完全迷路了。。。