此查询是针对codeigniter如何在laravel eloquent
中进行的 $this->db->select('*');
$this->db->from('countries cun');
$this->db->join('cities cit', 'cit.country_code=cun.country_code', 'left');
$this->db->join('city_states cits', 'cits.country_code=cun.country_code', 'left');
$this->db->join('timezone timz', 'timz.country_code=cun.country_code', 'left');
$this->db->where('cun.country',$id);
return $query = $this->db->get()->result();
答案 0 :(得分:1)
试试这个
return DB::table('countries AS cun')
->leftJoin('cities AS cit', 'cit.country_code', '=', 'cun.country_code')
->leftJoin('city_states AS cits', 'cits.country_code', '=', 'cun.country_code')
->leftJoin('timezone AS timz', 'timz.country_code', '=', 'cun.country_code')
->where('cun.country', $id)
->get();
雄辩模型
return Country::leftJoin('cities AS cit', 'cit.country_code', '=', 'countries.country_code')
->leftJoin('city_states AS cits', 'cits.country_code', '=', 'countries.country_code')
->leftJoin('timezone AS timz', 'timz.country_code', '=', 'countries.country_code')
->where('countries.country', $id)
->get();
答案 1 :(得分:0)
Countries
cities
- 雄辩的模特。
city_states
模型中的 timezone
,Countries
,public class MyClass{
public void print(){
system.out.println("Hi")
}
}
- relationships。