Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用“时出错”;其中不包括;方法[laravel]_Php_Laravel - Fatal编程技术网

Php 使用“时出错”;其中不包括;方法[laravel]

Php 使用“时出错”;其中不包括;方法[laravel],php,laravel,Php,Laravel,每当我运行此查询时,要返回不在另一个表中的数据,就会出现以下错误 BadMethodCallException in Macroable.php line 74: Method whereNotIn does not exist 质疑 $shipment_data_unassigned = Shipment::all()->where('status','=', $rulesetname) ->Where('shipment_cycle', '!=', 'closed')

每当我运行此查询时,要返回不在另一个表中的数据,就会出现以下错误

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

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

使用
all()
时,它执行查询并返回一个包含结果的集合。因此,当您链接更多方法时,实际上是在链接集合,而不是构建SQL查询。集合有一个过滤已经返回的结果的
where()
,但它们没有
whereNotIn()
方法

要在SQL中实现这一点,请删除
all()
调用,并将其替换为末尾的
get()

$shipment_data_unassigned = Shipment::where('status','=', $rulesetname)
    ->Where('shipment_cycle', '!=', 'closed')
    ->whereNotIn('ccctadm.Shipment.id',$assigned)->get();
使用
all()
时,它执行查询并返回一个包含结果的集合。因此,当您链接更多方法时,实际上是在链接集合,而不是构建SQL查询。集合有一个过滤已经返回的结果的
where()
,但它们没有
whereNotIn()
方法

要在SQL中实现这一点,请删除
all()
调用,并将其替换为末尾的
get()

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

谢谢,这么简单,你能告诉我get()和all()方法之间的区别吗?如果您有时间,@AhmadzIssa
all()
方法是一种静态方法,它是一种简单获取该模型数据库中每条记录的快捷方式。不能添加任何约束。一旦添加了诸如
shipping::where(…)
之类的约束,现在就可以使用querybuilder实例了。为了执行查询并获得结果,您需要在查询生成器实例上调用
get()
。@AhmadzIssa当您执行
shipping::all()
Laravel将立即执行
SELECT*FROM shipping
并返回一个包含所有装运的集合。Laravel中的集合基本上是一个功能更强大的数组,您可以对集合执行
where()
搜索,但都是在内存中完成的。要使“where”子句进入SQL查询,您需要在Laravel执行查询之前设置约束。因此,
shipping::where('status','=',$rulesetname)
将转换为
SELECT*FROM shipptation,其中status=?
。为了最终执行该查询,您需要使用
get()
方法进行非常清楚的解释。非常感谢你。我很感激。谢谢,这很简单,你能告诉我get()和all()方法之间的区别吗?如果您有时间,@AhmadzIssa
all()
方法是一种静态方法,它是一种简单获取该模型数据库中每条记录的快捷方式。不能添加任何约束。一旦添加了诸如
shipping::where(…)
之类的约束,现在就可以使用querybuilder实例了。为了执行查询并获得结果,您需要在查询生成器实例上调用
get()
。@AhmadzIssa当您执行
shipping::all()
Laravel将立即执行
SELECT*FROM shipping
并返回一个包含所有装运的集合。Laravel中的集合基本上是一个功能更强大的数组,您可以对集合执行
where()
搜索,但都是在内存中完成的。要使“where”子句进入SQL查询,您需要在Laravel执行查询之前设置约束。因此,
shipping::where('status','=',$rulesetname)
将转换为
SELECT*FROM shipptation,其中status=?
。为了最终执行该查询,您需要使用
get()
方法进行非常清楚的解释。非常感谢你。我很感激。