/** * Display a listing of the resource. * * @return Response */ public function index() { $q = ''; if (\Request::has('q') || \Request::has('location_id') || \Request::has('project_id') || \Request::has('nodegroup_id') || \Request::has('status') || \Request::has('poll_class')) { $nodes = \App\Node::where('id', '>', 0); // search by name or ip_address if (\Request::has('q')) { $q = trim(\Request::get('q')); $nodes = $nodes->where(function ($query) { $q = trim(\Request::get('q')); $query->where('name', 'RLIKE', $q)->orWhere('ip_address', 'RLIKE', $q); }); } // search by location_id if (\Request::has('location_id')) { $nodes = $nodes->where('location_id', \Request::get('location_id')); } // search by project_id if (\Request::has('project_id')) { $nodes = $nodes->where('project_id', \Request::get('project_id')); } // search by nodegroup_id if (\Request::has('nodegroup_id')) { $nodes = $nodes->where('nodegroup_id', \Request::get('nodegroup_id')); } // search by status if (\Request::has('status')) { switch (\Request::get('status')) { case 'up': $nodes = $nodes->where('ping_success', 100); break; case 'down': $nodes = $nodes->where('ping_success', 0); break; case 'unknown': $nodes = $nodes->where('ping_success', '<>', 100); $nodes = $nodes->where('ping_success', '<>', 0); break; default: break; } } // search by poll_class if (\Request::has('poll_class')) { if (\Request::get('poll_class') == 'Unknown') { $nodes = $nodes->where('poll_class', null); } else { $nodes = $nodes->where('poll_class', \Request::get('poll_class')); } } // search by sysObjectID if (\Request::has('sysObjectID')) { $nodes = $nodes->where('sysObjectID', \Request::get('sysObjectID')); } // paginate $nodes = $nodes->paginate(10); } else { $q = ''; $nodes = \App\Node::paginate(10); } return view('nodes.index', compact('nodes', 'q')); }