我有两个表Country和State查询State是
select state.id,state.state_name,Country.Country_name from country,state where state.country=country.id
此查询工作正常,我想将其转换为laravel查询构建器
答案 0 :(得分:0)
使用此:
DB::table('country')
->select('state.id', 'state.state_name', 'country.country_name')
->join('state', 'state.country', '=', 'country.id')
->get();
答案 1 :(得分:0)
在控制器功能中:
DB::table('country')->leftjoin('state', function ($join) {
$join('state', 'state.country', '=', 'country.id');})->get();
在控制器导入DB外观中:
use Illuminate\Support\Facades\DB;