首页 文章

如何解决此错误“[ErrorException] count():参数必须是一个数组或实现Countable的对象”?

提问于
浏览
0

[![我在我的机器上使用Windows 10 . 我安装了composer,然后在文档根目录中进行了laravel,即/ var / www

我还将-R 777 persmission给目录/ var / www中的文件夹laravel

然后我使用cd / var / www / laravel进入目录laravel并运行以下命令php artisan并且我在那里看到所有可用的命令 .

然后我输入php artisan db:seed并得到错误] 1] 1

enter image description here

<?php

       namespace Illuminate\Database\Console\Seeds;

       use Illuminate\Console\Command;
       use Illuminate\Database\Eloquent\Model;
        use Illuminate\Console\ConfirmableTrait;
      use Symfony\Component\Console\Input\InputOption;
      use Illuminate\Database\ConnectionResolverInterface as Resolver;

      class SeedCommand extends Command
   {
     use ConfirmableTrait;

    /**
 * The console command name.
 *
 * @var string
 */
protected $name = 'db:seed';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Seed the database with records';

/**
 * The connection resolver instance.
 *
 * @var \Illuminate\Database\ConnectionResolverInterface
 */
protected $resolver;

/**
 * Create a new database seed command instance.
 *
 * @param  \Illuminate\Database\ConnectionResolverInterface  $resolver
 * @return void
 */
public function __construct(Resolver $resolver)
{
    parent::__construct();

    $this->resolver = $resolver;
}

/**
 * Execute the console command.
 *
 * @return void
 */
public function fire()
{
    if (! $this->confirmToProceed()) {
        return;
    }

    $this->resolver->setDefaultConnection($this->getDatabase());

    Model::unguarded(function () {
        $this->getSeeder()->run();
    });
}

/**
 * Get a seeder instance from the container.
 *
 * @return \Illuminate\Database\Seeder
 */
protected function getSeeder()
{
    $class = $this->laravel->make($this->input->getOption('class'));

    return $class->setContainer($this->laravel)->setCommand($this);
}

/**
 * Get the name of the database connection to use.
 *
 * @return string
 */
protected function getDatabase()
{
    $database = $this->input->getOption('database');

    return $database ?: $this->laravel['config']['database.default'];
}

/**
 * Get the console command options.
 *
 * @return array
 */
protected function getOptions()
{
    return [
        ['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'DatabaseSeeder'],

        ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed'],

        ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
    ];
}

}

2 回答

  • 1

    当我用 PHP 7.2 安装了 laravel 时,我发现了这个错误,显然它已经doesn't support 7.2,尝试将你的 PHP 降级为 PHP 7.0 ,它对我有用 .

  • 0

    您要么降级到PHP7.1,要么至少使用Laravel v5.6 .

相关问题