Laravel 5 为什么在laravel中播种时会出现rand无法识别的错误

Laravel 5 为什么在laravel中播种时会出现rand无法识别的错误,laravel-5,Laravel 5,我正在尝试为我的DatabaseSeeder.php运行php artisan:migrate--seed,但我的终端中不断出现以下错误: InvalidArgumentException:未知的格式化程序“rand” 242 |抛出new\InvalidArgumentException(sprintf('Unknown formatter“%s”,$formatter)); 243| } 244| 245| /** 246 |*用令牌方法调用的结果替换令牌({{tokenNa

我正在尝试为我的DatabaseSeeder.php运行php artisan:migrate--seed,但我的终端中不断出现以下错误:

InvalidArgumentException:未知的格式化程序“rand”

242 |抛出new\InvalidArgumentException(sprintf('Unknown formatter“%s”,$formatter)); 243| } 244| 245| /** 246 |*用令牌方法调用的结果替换令牌({{tokenName}}')

下面是来自我的数据库种子php的代码

    <?php
use App\Question;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // $this->call(UsersTableSeeder::class);
        factory(App\User::class, 3)->create()->each(function($u){
            $u->questions()
              ->saveMany(
                  factory(App\Question::class, rand(1,5))->make()
            );
        });
    }
}

最好将
rand()
存储在工厂外。 尝试将代码更改为:

public function run()
{
    $number = rand(1,5);
    factory(App\User::class, 3)->create()->each(function($u) use ($number){
        $u->questions()
          ->saveMany(
              factory(App\Question::class, $number)->make()
        );
    });
}
public function run()
{
    $number = rand(1,5);
    factory(App\User::class, 3)->create()->each(function($u) use ($number){
        $u->questions()
          ->saveMany(
              factory(App\Question::class, $number)->make()
        );
    });
}