doudao7511
doudao7511
2019-08-15 20:06

类型错误:传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须是类型数组,给定整数

  • laravel
  • php

I'm using Laravel factories to seed my database and I can't figure out why this error is being thrown. (Shown at bottom).

This is my first post, so please let me know how I could have provided a more clear description of the issue :)

PollAnswerFactory.php

$factory->define(PollAnswer::class, function (Faker\Generator $faker) {

    $answer_text = $faker->word;
    $answer_order = rand(0,10);
    $question_id = rand(1,500);

    return [
        "answer_text" => $answer_text,
        "answer_order" => $answer_order,
        "question_id" => $question_id,
    ];
});

PollAnswer.php

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class PollAnswer extends Model {

    /**
     * @var bool Indicates if the model should be timestamped.
     */
    public $timestamps = false;

    /**
     * @var string The database table for this model.
     */
    protected $table = 'poll_answers';

    /**
     * The connection name for the model.
     *
     * @var string
     */
    protected $connection = 'poll_database';

    /**
     * The storage format of the model's date columns.
     *
     * @var string
     */
    protected $dateFormat = 'U';

    /**
     * The primary key(s) for the poll_answers table
     *
     * @var string
     */
    protected $primaryKey = 'answer_id';

    /**
     * @var array The fillable attributes of this model.
     */
    protected $fillable = [
        'answer_text',
        'answer_order',
        'question_id'
    ];

    /**
     * This establishes the eloquent one-to-many relationship
     *
     * @return HasMany
     */
    public function poll_result() {
        return $this->hasMany(PollResult::class);
    }

    /**
     * This establishes the eloquent (inverse) one-to-many relationship
     *
     * @return BelongsTo
     */
    public function poll_question() {
        return $this->belongsTo(PollQuestion::class);
    }

    }

PollSeeder.php

use Illuminate\Database\Seeder;
class PollSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {
         factory(PollAnswer::class, 1500)->create();

    }
}

PollController.php

public function index() 
{
$seeder = new PollSeeder();
$seeder->run();
}

Error Message: (1/1) FatalThrowableError Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, integer given, called in /var/www/vhosts/removed/www-root/core/library/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 681

Call Stack:

at Grammar->parameterize(3)
in Grammar.php line 681
at Grammar->Illuminate\Database\Query\Grammars\{closure}(3, 'answer_order')
at array_map(object(Closure), array('answer_text' => array('soluta', 'doloribus', 'quis'), 'answer_order' => 3, 'question_id' => 256), array('answer_text', 'answer_order', 'question_id'))
in Collection.php line 861
at Collection->map(object(Closure))
in Grammar.php line 682
at Grammar->compileInsert(object(Builder), array('answer_text' => array('soluta', 'doloribus', 'quis'), 'answer_order' => 3, 'question_id' => 256))
in Grammar.php line 697
at Grammar->compileInsertGetId(object(Builder), array('answer_text' => array('soluta', 'doloribus', 'quis'), 'answer_order' => 3, 'question_id' => 256), 'answer_id')
in Builder.php line 2155
at Builder->insertGetId(array('answer_text' => array('soluta', 'doloribus', 'quis'), 'answer_order' => 3, 'question_id' => 256), 'answer_id')
in Builder.php line 1283
at Builder->__call('insertGetId', array(array('answer_text' => array('soluta', 'doloribus', 'quis'), 'answer_order' => 3, 'question_id' => 256), 'answer_id'))
in Model.php line 722
at Model->insertAndSetId(object(Builder), array('answer_text' => array('soluta', 'doloribus', 'quis'), 'answer_order' => 3, 'question_id' => 256))
in Model.php line 687
at Model->performInsert(object(Builder))
in Model.php line 550
at Model->save()
in FactoryBuilder.php line 172
at FactoryBuilder->Illuminate\Database\Eloquent\{closure}(object(PollAnswer), 0)
in Collection.php line 339
at Collection->each(object(Closure))
in FactoryBuilder.php line 173
at FactoryBuilder->store(object(Collection))
in FactoryBuilder.php line 153
at FactoryBuilder->create()
in PollSeeder.php line 31
at PollSeeder->run()
in PollController.php line 35
at PollController->index()
at call_user_func_array(array(object(PollController), 'index'), array())
in Controller.php line 54
at Controller->callAction('index', array())
in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch(object(Route), object(PollController), 'index')
in Route.php line 212
at Route->runController()
in Route.php line 169
at Route->run()
in Router.php line 658
at Router->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in RefreshToken.php line 84
at RefreshToken->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Authenticate.php line 54
at Authenticate->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in ThrottleRequests.php line 57
at ThrottleRequests->handle(object(Request), object(Closure), 60, '1')
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php line 102
at Pipeline->then(object(Closure))
in Router.php line 660
at Router->runRouteWithinStack(object(Route), object(Request))
in Router.php line 635
at Router->runRoute(object(Request), object(Route))
in Router.php line 601
at Router->dispatchToRoute(object(Request))
in Router.php line 590
at Router->dispatch(object(Request))
in Kernel.php line 176
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
in Pipeline.php line 149
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php line 102
at Pipeline->then(object(Closure))
in Kernel.php line 151
at Kernel->sendRequestThroughRouter(object(Request))
in Kernel.php line 116
at Kernel->handle(object(Request))
in index.php line 49```
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答