Php Laravel雄辩,其中pivot null或小于
我在多对多关系的透视表中有一个名为closed的时间戳字段。我想获取关闭时间为null或小于特定时间的项目。 我尝试了以下方法:Php Laravel雄辩,其中pivot null或小于,php,laravel,laravel-5,eloquent,laravel-5.4,Php,Laravel,Laravel 5,Eloquent,Laravel 5.4,我在多对多关系的透视表中有一个名为closed的时间戳字段。我想获取关闭时间为null或小于特定时间的项目。 我尝试了以下方法: // In model public function jobEquipments($job, $one = false) { $nowDt = Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s')); if (!$one){ return $th
// In model
public function jobEquipments($job, $one = false)
{
$nowDt = Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s'));
if (!$one){
return $this->belongsToMany(Equipment::class, 'cavity_actions', 'cavity_id', 'equipment_id')
->wherePivot('job_id', $job)
->withPivot('created_at','aid')
->wherePivot('closed',null)
->orWherePivot('closed','<',date('Y-m-d H:i:s'))
->orderBy('pivot_created_at', 'desc');
}
....
//在模型中
公共功能作业设备($job,$one=false)
{
$nowDt=Carbon::createFromFormat('Y-m-dh:i:s',date('Y-m-dh:i:s');
如果(!$1){
返回$this->belongTomany(设备::类,“空腔动作”、“空腔id”、“设备id”)
->wherePivot('job_id',$job)
->withPivot('created_at','aid')
->wherePivot('closed',null)
->或wherepivot('closed',“尝试隔离或语句。尝试以下操作:
$this->belongsToMany(Equipment::class, 'cavity_actions', 'cavity_id', 'equipment_id')
->wherePivot('job_id', $job)
->withPivot('created_at','aid')
->where(function ($q) {
$q->where('cavity_actions.closed',null)
->orWhere('cavity_actions.closed','<',date('Y-m-d H:i:s'));
})
->orderBy('pivot_created_at', 'desc');
$this->belongtomany(设备::类,“空腔动作”、“空腔id”、“设备id”)
->wherePivot('job_id',$job)
->withPivot('created_at','aid')
->其中(函数($q){
$q->where('cover\u actions.closed',null)
->orWhere('convere\u actions.closed','至少适用于PostgreSQL(light\Database\Query\Grammars\PostgresGrammar):
#其中pivotIsNull
->wherePivot(SomeModelName::DELETED_AT,'与',DB::raw('null')没有区别
#其中PivotIsNotNull
->wherePivot(SomeModelName::DELETED_AT,'不同于',DB::raw('null'))
调用undefined method Illumb\Database\Query\Builder::orWhere Pivot()
好的,尝试使用Where和orWhere。我编辑了答案上次编辑有效,但它返回的结果与我认为的代码相同,没有隔离。对不起,我忘了正确地输出代码。它工作得很好,谢谢。