dounei5721 2017-03-09 23:38
浏览 352
已采纳

使用“whereNotIn”方法时出错[laravel]

whenever I run this query, to return data not in another table I get this error

BadMethodCallException in Macroable.php line 74:
Method whereNotIn does not exist

Query

  $shipment_data_unassigned = Shipment::all()->where('status','=', $rulesetname)
   ->Where('shipment_cycle', '!=', 'closed')
    ->whereNotIn('ccctadm.Shipment.id',$assigned);

What am I doing wrong ?

  • 写回答

1条回答 默认 最新

  • dongsu1539 2017-03-09 23:43
    关注

    When you use all() it executes the query and returns a collection with the results. So when you chain more methods you're actually chaining on a collection rather than building up the SQL query. Collections have a where() that filters the already returned results (not in SQL), but they do not have a whereNotIn() method.

    To do this all in SQL Remove the all() call and replace it with a get() at the end.

    $shipment_data_unassigned = Shipment::where('status','=', $rulesetname)
        ->Where('shipment_cycle', '!=', 'closed')
        ->whereNotIn('ccctadm.Shipment.id',$assigned)->get();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置