2016-05-19 8 views
0

このクエリは4つのテーブルは雄弁laravelに参加し

$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(); 

答えて

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(); 
+0

私の質問は、雄弁なモデルではないクエリビルダ –

+0

オーケーです。私は答えを更新しました。これをチェックし、これがあなたに役立つかどうか教えてください。 –

+0

kya cheezおかげで運が良かった –

0

See here

を試してみてください雄弁laravelでそれを作る方法をCodeIgniterのためのものです

Countries::with(["cities", "city_states", "timezone"])->where("country", $id)->get();

Countries - Eloquent Model - Eloquent Model。

citiescity_statestimezoneからCountriesモデルでrelationships