/** * Returns the collection of retrieved nodes by json response * * @param Request $request * @return Response */ public function searchJson(Request $request) { // Because of the searchable trait we are adding the global scopes from scratch $nodes = Node::withoutGlobalScopes()->typeMailing()->groupBy('id')->limit(10); $filter = $request->input('filter', 'all'); if ($filter !== 'all') { $nodes->withType($filter); } // Search must be last $nodes = $nodes->search($request->input('q'), 20, true)->get(); $results = []; foreach ($nodes as $node) { $results[$node->getKey()] = $node->getTitle(); } return response()->json($results); }