/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $filter = array_fill_keys($this->proposal->getAllColumnsNames(), ""); $stop_fields = array('filter', 'user_id'); $input = Input::all(); if (isset($input['filter']) && $input['filter'] == 'apply') { $filter = array_merge($filter, $input); Session::put("PROPOSALS_FILTER", $filter); } if (isset($input['filter']) && $input['filter'] == 'reset') { Session::forget('PROPOSALS_FILTER'); } if (isset($input['sort_value'])) { $sort = $input['sort_value']; $sort_dir = $input['sort_dir']; Session::put("PROPOSALS_SORT", array('value' => $sort, 'dir' => $sort_dir)); } $sort = Session::get('PROPOSALS_SORT'); if (isset($input['filter']) && $input['filter'] == 'reset') { Session::forget('PROPOSALS_FILTER'); } if (Session::has('PROPOSALS_FILTER')) { $filter = Session::get('PROPOSALS_FILTER'); $proposals = $this->proposal->where('id', '>', '0'); foreach ($filter as $k => $v) { if (!in_array($k, $stop_fields) && $v != '') { $proposals = $proposals->where($k, 'like', '%' . $v . '%'); } } if ($filter['user_id']) { $users = User::where('username', 'like', '%' . $filter['user_id'] . '%')->get(); $proposals = $proposals->whereIn('user_id', $users->pluck('id')->all()); } if (Session::has('PROPOSALS_SORT') && $sort['value'] != '') { $proposals = $proposals->orderBy($sort['value'], $sort['dir'] == '1' ? 'desc' : ''); } $proposals = $proposals->paginate(Settings::getValue('TABLE_ELEMENTS')); } else { if (Session::has('PROPOSALS_SORT') && $sort['value'] != '') { $proposals = $this->proposal->orderBy($sort['value'], $sort['dir'] == '1' ? 'desc' : 'asc'); } else { $proposals = $this->proposal; } $proposals = $proposals->paginate(Settings::getValue('TABLE_ELEMENTS')); } $sort_options = Proposal::getSortOptions(); return View::make('backend.proposals.index', compact("proposals", 'filter', 'sort_options', 'sort')); }