whereIn('model_type', [Tour::class, Flight::class]) ->with('admin') ->when($request->filled('model_type'), function ($query) use ($request) { $query->where('model_type', $request->input('model_type')); }) ->when($request->filled('action'), function ($query) use ($request) { $query->where('action', $request->input('action')); }) ->orderByDesc('created_at') ->paginate(20) ->withQueryString() ->through(function ($log) { $modelClass = $log->model_type; $relatedModel = $modelClass::find($log->model_id); $log->model_title = $relatedModel->title ?? '(حذف شده)'; $log->model_label = $log->model_type === Tour::class ? 'تور' : 'پرواز'; $log->model_edit_route = null; if ($relatedModel) { $log->model_edit_route = $log->model_type === Tour::class ? route('admin.tours.edit', $log->model_id) : route('admin.flights.edit', $log->model_id); } return $log; }); return view('admin.activity-logs.index', compact('logs')); } }