Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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 ModelFactory错误_Php_Laravel_Laravel 5_Laravel 5.4 - Fatal编程技术网

Php 设定种子时出现Laravel ModelFactory错误

Php 设定种子时出现Laravel ModelFactory错误,php,laravel,laravel-5,laravel-5.4,Php,Laravel,Laravel 5,Laravel 5.4,我的模型工厂: <?php $factory->define(App\Models\Customer::class, function (Faker\Generator $faker) { return [ 'name' => $faker->company, 'email' => $faker->unique()->safeEmail, '

我的模型工厂:

<?php        

    $factory->define(App\Models\Customer::class, function (Faker\Generator $faker) {
        return [
            'name' => $faker->company,
            'email' => $faker->unique()->safeEmail,
            'status'=> $faker->numberBetween($min = 0, $max = 2),
            'slug'=> $faker->slug,
        ];
    });
我得到了错误

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting '
  ]'
我已经尝试了我能想到的一切,但没有发现问题

编辑:

我忘了在前一天提到它工作得很好,但当我开始在不同的文件中添加更多的模型工厂时,它就坏了。然后我放弃了源代码管理中的所有更改,以100%确定我没有更改任何内容。唯一的另一个方面可能是.gitignore中的某些内容可能已更新且未回滚:

/node_modules
/public/storage
/public/hot
/storage/*.key
/.idea
Homestead.json
Homestead.yaml

问题似乎出在这一行:

'status'=> $faker->numberBetween($min = 0, $max = 2),
应该是:

'status'=> $faker->numberBetween(0, 2),

好吧,所以我找到了原因,觉得自己真的很傻,但还是把它贴在这里,以防有人追随我的脚步

问题是在database/factories文件夹中还有其他ModelFactories,运行php-artisan-db:seed似乎也会解析这些文件,即使它们没有在DatabaseSeeder类中引用。其中一个文件的一个或多个语法不正确,这导致了错误

我意识到这一点的唯一方法是在php artisan tinker中运行factory->create方法,它抛出的错误消息引用了另一个工厂定义


FWIW,然后我使用了为我的关系概述的方法-出于问题中提到的原因…

虽然可能不是有意的,但这不应该是语法错误。这只是在将两个变量传递到numberBetween方法时分配它们。@Marcin,仍然会得到相同的错误。用一些额外的背景信息更新了这个问题。我在你发布的代码中没有看到任何语法错误。但是,从错误消息来看,您似乎在某处有一个未关闭的数组。
'status'=> $faker->numberBetween($min = 0, $max = 2),
'status'=> $faker->numberBetween(0, 2),