【问题标题】:mb_strpos() expects parameter 1 to be string, object givenmb_strpos() 期望参数 1 是字符串,给定对象
【发布时间】:2022-01-27 02:29:37
【问题描述】:

mb_strpos() 期望参数 1 是字符串,给定对象 - 使用下面的查询在 eloquent 中使用 with 进行嵌套过滤来面对这个错误。

$columns = Column::with(['cards', function ($query) {
        $query->where(function ($query) {
            if (isset($_GET['status']) && $_GET['status'] != '') {
                $query->where('status', trim($_GET['status']));
            }
            })
            ->where(function ($query) {
            if (isset($_GET['date']) && $_GET['date'] != '') {
                $query->where('created_at', trim($_GET['date']));
            }
            });
    }])->get();

【问题讨论】:

  • mb_strpos() 未出现在您发布的代码中,因此我们不知道此错误发生在哪里。不过,信息很明确。您正在向它发送一个对象并且它需要一个字符串。你应该能够解决这个问题。

标签: php laravel eloquent


【解决方案1】:

您是否尝试过查询“卡片”关系?如果是,你可以试试这个查询

$columns = Column::with(['cards' => function ($query) {

【讨论】:

  • 您的查询正在将回调传递给第二个数组,您是否尝试将回调作为“卡片”的数组值传递?
  • laracasts.com/discuss/channels/laravel/…你能看到这个我已经详细讨论过这个问题。
猜你喜欢
  • 2020-06-01
  • 2015-06-27
  • 2020-11-22
  • 2018-08-07
  • 2017-08-30
  • 2018-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多