Laravel 等同于 SQL 查询的查询生成器?

Laravel Query builder equivalent to SQL query?

我有两个 table 国家和州,SQL 对州的查询是

select state.id,state.state_name,Country.Country_name from country,state where state.country=country.id

此查询运行良好,我想将其转换为 laravel 查询构建器

使用这个:

DB::table('country')
    ->select('state.id', 'state.state_name', 'country.country_name')
    ->join('state', 'state.country', '=', 'country.id')
    ->get();

在控制器函数中:

DB::table('country')->leftjoin('state', function ($join) {
            $join('state', 'state.country', '=', 'country.id');})->get();

在控制器中导入数据库外观:

use Illuminate\Support\Facades\DB;