public function projectsUserIsMember($userid) { $userInProjects = DB::table('project_user')->where('user_id', '=', $userid)->get(['project_id']); $wherein = []; foreach ($userInProjects as $value) { $wherein[] = $value->project_id; } return Project::whereIn('id', $wherein)->get(); }
public function getIndex($criteria = Null) { Session::put('step', '1'); Session::put('last_insert_id', ''); $searchKey = \Input::get('srch-term') ? \Input::get('srch-term') : Null; $projects = Project::whereIn('active', [0, 1]); if ($criteria != Null) { switch ($criteria) { case "active": $projects = Project::where('active', 1); break; case "inactive": $projects = Project::where('active', 0); break; case "featured": $projects = Project::where('featured', 1); break; case "suspended": $projects = Project::where('status', 1); break; case "flaged": $projects = Project::where('flag', 1); break; case "uflaged": $projects = Project::where('user_flagged', 1); break; } } if ($searchKey != Null) { $projects->Where(function ($query) use($searchKey) { //echo $searchKey; exit; $query->where('name', 'LIKE', '%' . $searchKey . '%'); }); } $results = $projects->orderBy('id', 'desc')->paginate($this->show_per_page); return view('admin.project.index', ['projects' => $results, 'searchKey' => $searchKey, 'dataStat' => $this->project_repo->projectDataStat()]); }
public function postSearch(Request $request) { $searchKey = $request->get('srch-term'); //DB::connection()->enableQueryLog(); $results = Project::whereIn('active', [0, 1])->Where(function ($query) use($searchKey) { $query->where('name', 'LIKE', '%' . $searchKey . '%'); })->paginate($this->show_per_page); //$queries = DB::getQueryLog(); if ($results) { return view('admin.project.index', ['users' => $results, 'result_count' => count($results), 'dataStat' => $this->project_repo->projectDataStat(), 'searchKey' => $searchKey]); } else { return Redirect::back()->with('message', 'No results found'); } }