search

Home  >  Q&A  >  body text

How to filter out the information with empty records in the joint query in the laravel framework?

Relationship definition function in model file Dis_Reocrd.php

    //1对多关系
    public function DisAccountRecord(){
        return $this->hasMany('Dis_Account_Record','Ds_Record_ID','Record_ID');
    }

Use the following statement to call

$builder = Dis_Record::where('Users_ID', $Users_ID)
                     ->with('DisAccountRecord')                            

At this time, we need to filter out the empty result set of DisAccountRecord(). How should we do this?

黄舟黄舟2758 days ago377

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 16:50:45

    hasMany You can add conditions

    Similar to

     public function DisAccountRecord(){
            return $this->hasMany('Dis_Account_Record','Ds_Record_ID','Record_ID')
                    ->whereNotNull('updated_at')
        }

    reply
    0
  • Cancelreply