Skip to content

Instantly share code, notes, and snippets.

@brunokunace
Created November 6, 2017 20:37
Show Gist options
  • Save brunokunace/240b61b30416cce101b6aed5b0ca6e9e to your computer and use it in GitHub Desktop.
Save brunokunace/240b61b30416cce101b6aed5b0ca6e9e to your computer and use it in GitHub Desktop.
public function test()
{
$cityName = "Viamão";
$stateInitials = "RS";
$states = DB::table('estado')
->join('cidade', function ($join) use ($cityName, $stateInitials) {
$join->on('cidade.Estado_ID', '=', 'estado.ID')
->where('cidade.NomeCidade', '=', $cityName);
})
->where('estado.Sigla', '=', $stateInitials)
->toSQL();
return response()->json($states, 200);
}
//Select cidade.ID
//from estado
//Inner Join cidade on cidade.Estado_ID = estado.ID and cidade.NomeCidade = "Viamão"
//Where estado.Sigla = "RS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment