Laravel 数据库外观 select 动态
Laravel DB facade select dynamicaly
我正在尝试在 Laravel 中使用 db facade 创建一个动态的 select。
$EntrepriseSurBAseDuNace = DB::table ('enterpriseAddress')
->join('enterpriseEnterprise', 'enterpriseEnterprise.EnterpriseNumber', '=', 'enterpriseAddress.EntityNumber','LEFT OUTER')
->select('EntityNumber')
->where([
['Zipcode','=',$CodePostal],
['enterpriseEnterprise.StartDate ','=',$DateCreation],
])
->get();
如果 arrays/Vars 不为空,我想添加连接,如下所示:
if(isset($Var){
->join ......
}
或
if(isset($Array){
->join ......
}
但我不能在请求中这样做。
Thak 寻求帮助,对不起我的英语。
感谢大卫:
$queryTest = DB::table ('enterpriseAddress');
if (isset($RechercheRequete['CodePostal']))
{
$CodePostal = $RechercheRequete['CodePostal'];
$queryTest->where('enterpriseAddress.Zipcode','=', $CodePostal);
}
$result = $queryTest->select('EntityNumber') ->get(); dd($result);
exit();
$query = DB::table ('enterpriseAddress');
if (your-condition) {
$query->join(...
} elseif ('other condition') {
$query->join(...
}
$query->select('EntityNumber')
->where([
['Zipcode','=',$CodePostal],
['enterpriseEnterprise.StartDate ','=',$DateCreation],
])->get();
我正在尝试在 Laravel 中使用 db facade 创建一个动态的 select。
$EntrepriseSurBAseDuNace = DB::table ('enterpriseAddress')
->join('enterpriseEnterprise', 'enterpriseEnterprise.EnterpriseNumber', '=', 'enterpriseAddress.EntityNumber','LEFT OUTER')
->select('EntityNumber')
->where([
['Zipcode','=',$CodePostal],
['enterpriseEnterprise.StartDate ','=',$DateCreation],
])
->get();
如果 arrays/Vars 不为空,我想添加连接,如下所示:
if(isset($Var){
->join ......
}
或
if(isset($Array){
->join ......
}
但我不能在请求中这样做。 Thak 寻求帮助,对不起我的英语。
感谢大卫:
$queryTest = DB::table ('enterpriseAddress');
if (isset($RechercheRequete['CodePostal']))
{
$CodePostal = $RechercheRequete['CodePostal'];
$queryTest->where('enterpriseAddress.Zipcode','=', $CodePostal);
}
$result = $queryTest->select('EntityNumber') ->get(); dd($result);
exit();
$query = DB::table ('enterpriseAddress');
if (your-condition) {
$query->join(...
} elseif ('other condition') {
$query->join(...
}
$query->select('EntityNumber')
->where([
['Zipcode','=',$CodePostal],
['enterpriseEnterprise.StartDate ','=',$DateCreation],
])->get();