done fixing search -> next review
This commit is contained in:
parent
c005da49af
commit
8c1663f9c3
@ -97,6 +97,7 @@ class DashboardController extends Controller
|
||||
$filterUnit = request('unitKerja');
|
||||
$subUnit = request('subUnit');
|
||||
$keyword = request('keyword');
|
||||
$hasKeyword = !empty($keyword);
|
||||
$subArray = $subUnit ? explode(',', $subUnit) : [];
|
||||
$katArray = $kategori ? explode(',', $kategori) : [];
|
||||
$katDok = MasterKategori::when($katArray, fn($q) => $q->whereIn('master_kategori_directory_id', $katArray))->where('statusenabled', true)->select('master_kategori_directory_id', 'nama_kategori_directory')->get();
|
||||
@ -154,18 +155,21 @@ class DashboardController extends Controller
|
||||
|
||||
} elseif ($aksesAll) {
|
||||
/* all akses */
|
||||
$unitKerja = UnitKerja::where('statusenabled', true)->with([ // muat relasi
|
||||
'subUnitKerja' => fn($q) => $q->with([ // sub-unit
|
||||
'fileDirectory' => fn($f) => $f->whereNotNull('status_action')->when($keyword, fn($q) =>
|
||||
$q->where('file', 'ilike', "%{$keyword}%")
|
||||
)
|
||||
])
|
||||
$unitKerja = UnitKerja::where('statusenabled', true)
|
||||
->when($hasKeyword, fn($q) => $q->whereHas('subUnitKerja.fileDirectory', fn($f) => $applyFileQuery($f)))
|
||||
->with([ // muat relasi
|
||||
'subUnitKerja' => fn($q) => $q
|
||||
->when($hasKeyword, fn($sq) => $sq->whereHas('fileDirectory', fn($f) => $applyFileQuery($f)))
|
||||
->with([ // sub-unit
|
||||
'fileDirectory' => fn($f) => $applyFileQuery($f)
|
||||
])
|
||||
])
|
||||
->select('id', 'name')
|
||||
->get();
|
||||
|
||||
} elseif ($allowedUnitIds) {
|
||||
$unitKerja = UnitKerja::where('statusenabled', true)
|
||||
->when($hasKeyword, fn($q) => $q->whereHas('subUnitKerja.fileDirectory', fn($f) => $applyFileQuery($f)))
|
||||
->where(function ($q) use ($allowedUnitIds, $applyFileQuery) {
|
||||
if ($allowedUnitIds && $allowedUnitIds->isNotEmpty()) {
|
||||
$q->whereIn('id', $allowedUnitIds);
|
||||
@ -181,6 +185,7 @@ class DashboardController extends Controller
|
||||
|
||||
} else {
|
||||
$unitKerja = UnitKerja::where('statusenabled', true)
|
||||
->when($hasKeyword, fn($q) => $q->whereHas('subUnitKerja.fileDirectory', fn($f) => $applyFileQuery($f)))
|
||||
->where(function ($q) use ($authUnit, $applyFileQuery) {
|
||||
if ($authUnit) {
|
||||
$q->where('id', $authUnit);
|
||||
@ -188,8 +193,8 @@ class DashboardController extends Controller
|
||||
$q->orWhereHas('subUnitKerja.fileDirectory', fn($f) => $applyFileQuery($f));
|
||||
})
|
||||
->with([ // 1. sub-unit milik user
|
||||
'subUnitKerja' => fn($q) => $q->where(function ($sq) use ($authSub, $applyFileQuery) {
|
||||
if ($authSub) {
|
||||
'subUnitKerja' => fn($q) => $q->where(function ($sq) use ($authSub, $applyFileQuery, $hasKeyword) {
|
||||
if ($authSub && !$hasKeyword) {
|
||||
$sq->where('id', $authSub);
|
||||
}
|
||||
$sq->orWhereHas('fileDirectory', fn($f) => $applyFileQuery($f));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user