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

2024-03-06

我正在使用 Laravel 工厂来为我的数据库播种,但我不明白为什么会抛出这个错误。 (显示在底部)。

这是我的第一篇文章,所以请让我知道如何提供更清晰的问题描述:)

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,
    ];
});

投票答案.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();

    }
}

轮询控制器.php

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

错误信息: (1/1) 致命抛出错误 类型错误:传递给 Illuminate\Database\Grammar::parameterize() 的参数 1 必须是数组类型,给定整数,在 /var/www/vhosts/removed/www-root/core/library/vendor/laravel/ 中调用Framework/src/Illuminate/Database/Query/Grammars/Grammar.php 第 681 行

调用堆栈:

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```

更改这一行:

$answer_text = $faker->words;

To this:

$answer_text = $faker->word;

The words生成器返回引发错误的随机单词数组。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • PHP MYSQL文件内容转义问题

    我正在尝试使用 php 将 pdf 文件上传到 mysql 数据库中 除了文件内容之外 一切都很好 无论我如何尝试转义特殊字符 查询总是失败 主要是 未知命令 n 我使用过addslashes mysql real escape strin
  • 在 CodeIgniter 中将数组与 Calendar 类一起使用

    我正在尝试为我的日历应用程序创建一个相当复杂的数组 它应该包含日期 日期名称 类型 和事件 如果有 我已经创建了这个 dates 22 day gt Friday type gt weekday 23 day gt Saturday typ
  • PHP 中的 Europe/London 和 UTC 有区别吗? [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我知道 UTC 和 GMT 实际上是
  • Eloquent 模型中的 UUID 主键存储为 uuid 但返回为 0

    我有一个 mysql 表 其中使用 UUID 作为主键 这是创建迁移 Schema create people function Blueprint table table gt uuid id table gt primary id ta
  • while 循环中的表并排

    in a while loop its creating a list of heading and image links i want to display it as side by side like in following im
  • PHP 中给定日期的下一个工作日

    有人有一个 PHP 代码片段来计算给定日期的下一个工作日吗 例如 需要如何转换 YYYY MM DD 才能找到下一个工作日 例子 对于 03 04 2011 DD MM YYYY 下一个工作日是 04 04 2011 对于 2011 年 4
  • 在 Windows 中使用 PHP 创建受密码保护的 Zip 文件

    我正在 PHP 中创建给定文件的 zip 文件 下面是函数 function create zip file file name zip new ZipArchive zip name file name zip Zip name zip
  • PHP 数组到 JavaScript 数组

    假设我在 php 中有这个数组 cities array Caracas gt array air gt array 4 3 5 Working Days Saturday sea gt array 18 3 5 Days Wednesda
  • PHP比较两个字符串的随机位置

    PHP比较两个字符串 示例我得到了一串数字 1 2 2 1 and another is 2 1 2 1 结果是 true 因为它只是 1 2 2 1 和 2 2 1 1 的位置洗牌 但如果该值为 1 2 2 2 and another i
  • 如何在 PHP 中使用 file_get_contents 获取图像的 MIME 类型

    我需要获取图像的 MIME 类型 但我只有图像的正文file get contents 是否有可能获取 MIME 类型 是的 你可以这样得到它 file info new finfo FILEINFO MIME TYPE mime type
  • 在 WooCommerce 管理订单项目上显示产品自定义字段(也适用于可变产品)

    基于在 WooCommerce 的订单编辑页面上显示自定义字段 https stackoverflow com questions 56259910 show custom fields on the order editing page
  • PhpPresentation imagecreatefromstring():数据不是可识别的格式 - PHP7.2

    我正在尝试使用 PhpPresentation 来阅读sample pptx使用文档中为读者提供的简单说明进行文件处理 我得到 imagecreatefromstring Data is not in a recognized format
  • 获取url,给定的url重定向到

    我从 rss 链接中挖掘数据并获得一堆网址 例如 http feedproxy google com r electricpig 3 qoF8XbocUbE http feedproxy google com r electricpig 3
  • 使用 Laravel 4 验证多个文件上传

    如何在 Laravel 4 中验证上传文件的数组 我已将其设置为允许多个文件 并且已测试这些文件是否存在于 Input file files 数组中 但如何验证每个文件呢 这是我尝试过的 notesData array date gt In
  • WordPress 中的 add_action 函数

    嗯 我正在学习创建一个 WordPress 插件 我下载了一个并阅读了代码 然后我看到了这个 我假设 foo 是它将添加操作的标签 但是 array 到底是做什么的呢 add action foo array foo1 foo2 我在看ht
  • PHP MySql 百分比

    我的问题是关于百分比 我不是专家 所以我会尽力以更好的方式进行解释 我的 mysql 服务器中有一个表 假设有 700 条记录 如下所示 Name country language Birth Lucy UK EN 1980 Mari Ca
  • gmail 不断阻止 PHPmailer 登录

    我将在接下来的 8 小时内部署一个网站 而 Gmail 刚刚停止接受 PHPmailer 登录我的帐户 起初 它在测试过程中工作了几个小时 然后 它就停止工作了 我已经允许所有允许不太安全的应用程序从 gmail 登录 但它仍然不允许 ph
  • 检查php中位字段是否打开的正确方法是什么

    检查位字段是否打开的正确方法是什么 在 php 中 我想检查来自 db mysql 的位字段是否打开 这是正确的方法吗 if bit 1 还有其他方法吗 我看到有人使用代码ord http jameslow com 2008 08 12 m
  • openssl_pkey_get_details($res) 不返回公共指数

    我在用着这个例子 https stackoverflow com a 12575951 2016196使用 php 生成的密钥进行 javascript 加密openssl图书馆 但是 details openssl pkey get de
  • 搜索引擎如何找到相关内容? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 Google 在解析网络时如何找到相关内容 例如 Google 使用 PHP 原生 DOM 库来解析内

随机推荐