query('actor', '')); $action = trim((string) $request->query('action', '')); $q = trim((string) $request->query('q', '')); $from = $request->date('from'); $to = $request->date('to'); $perPage = max(10, min(200, (int) $request->query('per_page', 25))); $entries = AuditLog::query() ->when($actor !== '', fn ($b) => $b->where('actor', 'like', "%{$actor}%")) ->when($action !== '', fn ($b) => $b->where('action', $action)) ->when($q !== '', fn ($b) => $b->where(function ($b) use ($q) { $b->where('target', 'like', "%{$q}%")->orWhere('target_dn', 'like', "%{$q}%"); })) ->when($from, fn ($b) => $b->where('created_at', '>=', $from->startOfDay())) ->when($to, fn ($b) => $b->where('created_at', '<=', $to->endOfDay())) ->orderByDesc('created_at') ->orderByDesc('id') ->paginate($perPage) ->withQueryString(); return view('admin.audit.index', [ 'entries' => $entries, 'actions' => AuditLog::query()->select('action')->distinct()->orderBy('action')->pluck('action'), 'filters' => compact('actor', 'action', 'q') + [ 'from' => $request->query('from'), 'to' => $request->query('to'), ], ]); } }