Laravel:搜索关系数据

I have the following method in the same model. And i have another table call pet_tracking, There is a column named microchip, I have to search that column.

public function petInsurance(){
    return $this->hasOne('App\PetInsurance');
}

public function petTracking(){
    return $this->hasOne('App\PetTracking');
}

public function searchFoundPet($mpc_security, $microchip, $rabies_id,$vet_tag){

    $query = $this->with('petInsurance', 'petTracking');

    if ($microchip){
        $query->orWhere('microchip','like', $microchip);
    }

    pets = $query->get();
    return $pets;
}

The exception is Column not found: 1054 Unknown column 'microchip' in 'where clause'.

You have to use a JOIN: https://laravel.com/docs/5.6/queries#joins

Something like this (if your code shows the Pet model):

$query->join('pet_tracking', 'pet.id', '=', 'pet_tracking.pet_id');