【问题标题】:How to solve Type error: Argument 1 passed to Rinvex\Repository\Repositories\EloquentRepository::findWhereNotIn() must be of the type array?如何解决类型错误:传递给 Rinvex\Repository\Repositories\EloquentRepository::findWhereNotIn() 的参数 1 必须是数组类型?
【发布时间】:2017-07-22 07:52:23
【问题描述】:

我的查询是这样的:

$this->user_repository->findWhereNotIn('id', [1, 2, 3, 4]);

执行时出现如下错误:

[Symfony\Component\Debug\Exception\FatalThrowableError] 类型 错误:参数 1 传递给 Rinvex\Repository\Repositories\EloquentRepository::findWhereNotIn() 必须是数组类型,给定字符串,调用 C:\xampp\htdocs\myshop\app\Console\Commands\Check.php 第 48 行

而在教程https://github.com/rinvex/repository#findwherenotin 中,看起来我的查询是正确的

我该如何解决?

【问题讨论】:

  • Argument 1 指的是id 不是数组
  • 尝试改用['id']
  • @Onix,它不起作用。存在错误:[ErrorException] Invalid argument supplied for foreach()
  • @Machavity,我改成这样:$this->user_repository->findWhereNotIn(['id'], [1, 2, 3, 4]);,但它不起作用
  • 不应该是 whereNotIn 而不是 findWhereNotIn 吗? laravel.com/docs/5.4/queries#where-clauses

标签: php laravel repository laravel-5.3 laravel-eloquent


【解决方案1】:

您在第一个参数中将列名作为字符串传递,然后在第二个参数中将值作为数组传递,而 rinvex/repository findWhereNotIn as per the docs 的正确语法是同时传递列名和值将第一个参数作为关联数组如下:

$repository->findWhereNotIn(['id', [1, 2, 5, 8]]);

注意它们是如何通过的:['id', [1, 2, 5, 8]]

【讨论】:

猜你喜欢
  • 2017-01-14
  • 1970-01-01
  • 2017-09-05
  • 2020-01-06
  • 2018-04-19
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
  • 2017-12-17
相关资源
最近更新 更多