传递给Illuminate \ Database \ Query \ Builder :: insert()的参数1必须为数组类型,给定null

时间:2019-05-02 08:58:46

标签: laravel-5 database-migration

下午好,

我有一个问题,我已经拖延了几天,似乎无法理解我的意思。只是想知道是否有人可以指出我正确的方向。我在用着 :  -Laravel版本:5.8。  -PHP版本:7.2.5  -数据库驱动程序和版本:mysql 有什么建议我做错了吗? 感谢您的答复!

Stacktrace:

Symfony\Component\Debug\Exception\FatalThrowableError  : Argument 1 passed to Illuminate\Database\Query\Builder::insert() must be of the type array, null given, called in C:\xampp\htdocs\Laravel\crm\database\migrations\2018_07_18_054859_create_counters_table.php on line 28 at C:\xampp\htdocs\Laravel\crm\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:2611
    2607|      *
    2608|      * @param  array  $values
    2609|      * @return bool
    2610|      */
  > 2611|     public function insert(array $values)
    2612|     {
    2613|         // Since every insert gets treated like a batch insert, we will make sure the
    2614|         // bindings are structured in a way that is convenient when building these
    2615|         // inserts statements by verifying these elements are actually an array.

  Exception trace:

  1   Illuminate\Database\Query\Builder::insert()
      C:\xampp\htdocs\Laravel\crm\database\migrations\2018_07_18_054859_create_counters_table.php:28

  2   CreateCountersTable::load()
      C:\xampp\htdocs\Laravel\crm\database\migrations\2018_07_18_054859_create_counters_table.php:23

  Please use the argument -v to see more details.

这是我的018_07_18_054859_create_counters_table.php代码

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCountersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('counters', function (Blueprint $table) {
            $table->increments('id');
            $table->string('key')->unique();
            $table->string('prefix')->unique();
            $table->integer('value');
            $table->timestamps();
        });
        $this->load();
    }

    protected function load()
    {
        DB::table('counters')->insert(config('crm.counters'));
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('counters');
    }
}

0 个答案:

没有答案