- Düzenlendi
Merhabalar sorguda kullandığım where has kısmını sadece çalıştırdığımda sonuçlar doğru geliyor ama aşağıda ki if li kısımlar da sorguya dahil olunca üstteki wherehas'a bakmaksızın her şeyi getiriyor bir türlü çözemedim yardımcı olur musunuz ?
$joinLife = $request->input('join_life');
$disneyLicences = $request->input('disney_licences');
$companyId = $request->input('company_id');
$instructionTypeId = $request->input('instructionTypeId');
$result = Csr::with(['supplier_company:id,name', 'csr_process', 'csr_process.instructions']);
$result->whereHas('csr_process.instructions', function ($q) use ($instructionTypeId) {
$q->where('instruction_type.id', $instructionTypeId);
});
if ($joinLife && count($joinLife) && !in_array(1, $joinLife)) {
if ($joinLife) {
$result->whereJsonContains('join_life', $joinLife);
}
}
if ($companyId) {
$result->whereJsonContains('company_id', $companyId);
}
$result->where('status', '!=', 1);
if ($disneyLicences) {
if ($disneyLicences["license_id"]) {
foreach ($disneyLicences["license_id"] as $license){
$result->orWhere('disney_licences->license_id',$license);
}
}
if ($disneyLicences["disney_id"]) {
foreach ($disneyLicences["disney_id"] as $disney){
$result->orWhere('disney_licences->disney_id',$disney);
}
}
}
$result = $result->get()->toArray();
return Output::success($result);