Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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中使用where notin和with?_Php_Laravel - Fatal编程技术网

Php 如何在Laravel中使用where notin和with?

Php 如何在Laravel中使用where notin和with?,php,laravel,Php,Laravel,这是我的查询创建雄辩,我需要得到材料,是在日期可用 我从这里开始: 如何修复这些错误 Material::with(['orders_material' => function($query) use ($begin_date, $end_date, $begin_hour, $hour_final) { $query->whereNotIn( $query->where('date_begin', '>=', $begin_date)

这是我的查询创建雄辩,我需要得到材料,是在日期可用

我从这里开始:

如何修复这些错误

Material::with(['orders_material' => function($query)  use ($begin_date,
    $end_date, $begin_hour, $hour_final) 

 {
    $query->whereNotIn(
    $query->where('date_begin', '>=', $begin_date)
    ->where('date_begin', '<=', $end_date)
    ->where('date_final', '>=', $begin_date)
    ->where('date_final', '<=', $end_date)
    ->where('hour_begin', '>=', $begin_hour)
    ->where('hour_begin', '<=', $hour_final)
    ->where('hour_final', '>=', $begin_hour)
    ->where('hour_final', '<=', $hour_final);
    //->wherePivot('Material_id', null)
    //->wherePivot('Orders_id', null)
    );
  }
Material::with(['orders\u Material'=>函数($query)use($begin\u date,
$end\u date、$begin\u hour、$hour\u final)
{
$query->whereNotIn(
$query->where('date\u begin','>=',$begin\u date)
->其中('date\u begin','=',$begin\u date)
->其中('date\u final','=',$begin\u hour)
->其中('hour\u begin','=',$begin\u hour)

->其中('hour_final','
whereHas
是本例中的适当子句

此外,在查询介于最小值和最大值之间的值时,请使用
whereBetween
。这将大大简化您的查询:

Material::whereHas(['orders_material' => function($query) use ($begin_date, $end_date, $begin_hour, $hour_final) {
    $query->whereBetween('date_begin', [$begin_date, $end_date])
          ->whereBetween('date_final', [$begin_date, $end_date])
          ->whereBetween('hour_begin', [$begin_hour, $hour_final])
          ->whereBetween('hour_final', [$begin_hour, $hour_final]);
})->get();

whereHas
是本例中的适当子句

此外,在查询介于最小值和最大值之间的值时,请使用
whereBetween
。这将大大简化您的查询:

Material::whereHas(['orders_material' => function($query) use ($begin_date, $end_date, $begin_hour, $hour_final) {
    $query->whereBetween('date_begin', [$begin_date, $end_date])
          ->whereBetween('date_final', [$begin_date, $end_date])
          ->whereBetween('hour_begin', [$begin_hour, $hour_final])
          ->whereBetween('hour_final', [$begin_hour, $hour_final]);
})->get();

您收到的错误是什么?您必须使用
get()
才能获得结果您使用的WhereNotIn不正确,应该是
$query->WhereNotIn('column\u name',$someArrayHere)
@HelloSpeakman它是
Material::with(['orders\u Material'=>->WhereNotIn('Material\u id',function$q)use($begin_date、$end_date、$begin_hour、$hour_final){$q->where('date_begin','>=',$begin_date)
,但列名称是一个轴名称,我应该选择什么?你收到了什么错误?你必须使用
get()
来获得结果你使用的where不正确,应该是
$query->where不正确('column\u name',$someArrayHere)
@HelloSpeakman它是
Material::with(['orders\u Material'=>->-whereNotIn('Material\u id',function($q)use($begin\u date,$end\u date,$begin\u hour,$hour\u final){$q->where('date\u begin,'>=',$begin\u date)
,但column\u name是一个轴心名称,我应该选择什么?行了!谢谢!)工作!谢谢!:)